0

I have an app in vapor and I have a long running job lets say UpdateSomething and I want this job to be on one queue only, I don't want it to run concurrently.

class UpdateSomething implements ShouldQueue
{
    use Dispatchable;
    use Batchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;
    
    public $tries = 30;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        
    }

    public function middleware(): array
    {
        return [(new WithoutOverlapping(get_class($this)))->releaseAfter(1)];
    }

So I have here 30 tries and each try will retry after 1 second. Is this the right way to do this? Do I need to run expireAfter? What's the purpose of expireAfter?

1 Answer 1

1

Your implementation is mostly correct. The purpose of expireAfter is to ensure the lock is released in case the job fails unexpectedly, preventing it from being locked indefinitely. This would allow similar jobs to run even if the previous job did not complete successfully. You should define a duration longer than the expected completion time of the job to ensure the lock remains valid while the job is running but does not persist unnecessarily.

https://laravel.com/docs/11.x/queues#preventing-job-overlaps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.