dongmaijie5200 2016-10-23 20:09
浏览 114

Laravel - 仅在相同的上一个任务完成时运行计划任务

I was wondering if Laravel has a built in function to only run a scheduled task if the previous has finished.

I have a need to run a specific task every few seconds, but the task relies on querying another host that may at some point lose connection.

There are a couple of ways I thought about doing this, if there isn't:

  1. Having the task just put the job into the queue
  2. Having a flag saved (Either as a file or in the db), that is set at the start of the task, and unset at the finish.

Just hoping the task scheduler has something built in before I go down either of those routes ...

  • 写回答

1条回答 默认 最新

  • dongpai2754 2016-10-24 19:15
    关注

    Found the answer in the Docs :D

    https://laravel.com/docs/5.3/scheduling

    excerpt:

    Preventing Task Overlaps

    By default, scheduled tasks will be run even if the previous instance of the task is still running. To prevent this, you may use the withoutOverlapping method:

    $schedule->command('emails:send')->withoutOverlapping();
    

    In this example, the emails:send Artisan command will be run every minute if it is not already running. The withoutOverlapping method is especially useful if you have tasks that vary drastically in their execution time, preventing you from predicting exactly how long a given task will take.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决