doubiao1734 2019-05-04 08:45
浏览 42
已采纳

如何从给定时间开始laravel的调度程序?

I need to run certain commands after 2 days of another time that I read from database in laravel. I checked out the laravel's scheduler documentation but could not find anything related my problem.

How can I set up a scheduler relative to another time? I want to read a time/date from database and schedule a command based on this time. Also, It is not repetitive. It will only run once.

  • 写回答

1条回答 默认 最新

  • dongtuo5262 2019-05-04 09:05
    关注

    I think the best you can do is to setup a queued job. When you need to dispatch it (whenever it is in a scheduled task or not, it doesn't matter), you just dispatch it with a delay. It is well explained in the queue section of the documentation, right here: https://laravel.com/docs/5.7/queues#delayed-dispatching

    In your case, you can dispatch the job using this Carbon instance as a delay: now()->addDays(2). Two days later, the job will be executed :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示