0

I have job delayed in default redis queue and i want to remove it when model's status is updated to some value.

So i'm using updated observer:

     /**
     * If status change from active to draft remove delayed job
     *
     * @param  Draw  $draw
     */
    public function updated(Draw $draw)
    {
        $originalStatus = $draw->getOriginal('status');
        $newStatus = $draw->status;

        if ($originalStatus === 'active' && $newStatus === 'draft') {
            $job = Redis::get('App\Models\Draw:' . $draw->id);
            $job->delete();
        }
    }

With this code $job is always null. Do you know how i can get my job from redis default queue ? I don't know what redis key i need to use to fetch the specific job

1
  • You can't get the job like this, delayed jobs are kept in sorted set. Please check this answer stackoverflow.com/a/62905143/2188922 Commented Dec 1, 2020 at 18:53

1 Answer 1

1

Maybe the proper/easy way to terminate a job should be to check the status inside the job when it is running, and deciding there what the job should do according to the status.

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

2 Comments

Yes, i thought about it but i don't know if it's the more cleaner approach
Checking inside the job you fully own the code and can even write a test on it but, checking the redis table your are dealing with how the framework store the job and it may be subject to change. This is not your code but the internal Laravel code that you don't own

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.