laravel-async-queue icon indicating copy to clipboard operation
laravel-async-queue copied to clipboard

Prevent to exec a job before finish other

Open swim89 opened this issue 5 years ago • 0 comments

Hi to everyone, I have a problem using this library. I know that it can help me to exec jobs without waiting the others ends.

But sometimes I need to wait. For example, I put Job1 into queue "memberships" and after I put Job2 into the same queue. Into the handle of Job2 I put a code that check if there are other jobs in the DB table, if yes, I use the release method to put it again in queue. The problem is that if the Job1 finishes it execution, the Job2 doesn't starts...

Here my code:

    $result = DB::table("jobs")->where("queue", "=", "memberships")->where("payload", "NOT LIKE", "%ApiMemberships%");        
    
    $count = $result->count();        
    \Log::debug("Jobs: " . $count);
    if ($count >= 1) {
        \Log::debug("Try again in 1min.");
        $this->release(60);
    }

swim89 avatar Apr 27 '19 15:04 swim89