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

Devio__
  • 79
  • 2
  • 7
  • You can't get the job like this, delayed jobs are kept in `sorted set`. Please check this answer https://stackoverflow.com/a/62905143/2188922 – Ersoy Dec 01 '20 at 18:53

1 Answers1

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.

ml59
  • 1,495
  • 1
  • 9
  • 10
  • Yes, i thought about it but i don't know if it's the more cleaner approach – Devio__ Dec 01 '20 at 16:57
  • 1
    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 – ml59 Dec 01 '20 at 17:07