Repeatable job for Laravel json api

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 15:22:35

you can in AfterInsertJob->handle, on execution, create new queue:

$need_to_work = true;
.....

if( $need_to_work ){
AfterInsertJob::dispatch()->delay(3);
}

Why using a job to to the Task. Just run a scheduled command which checks whatever requirement you have.

Add a flag on the record the user creates. Check this flag in the command you write and perform the task required. If the user does whatever he needs to to, set the flag and your command will ignore this entry. If not it will be done until it is set.

If it is required exactly 24 hours after creation you can check creation date (and multiple of that) and the flag. But there are surly other ways too.

Update:

After reading your comment, I have another idea which can suit your needs better. You can use two things.

  1. delay
  2. number of retries / max attempts

delay is a method called why dispatching

max attempts is a proptery of the job class by the name of ´tries`

Your job will check whatever it has to check, and if the requirements are NOT met by the user you will let the job fail. If that is so it will be pushed back onto the queue with the delay of 24 hours. This will repeat until the number of "max attempts" has been reached.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!