1
我目前有一项任务,从我的网站收集使用统计数据并设置为自动将它们发送给客户端。本月第一个工作日的计划任务
问题是,本月的第一天可能是非工作日,我认为这不是一场灾难,但看起来有点不专业。
这是我是如何安排它目前:
$schedule
->command("report", [ "--email" => "[email protected]" ]) //My command which accepts the email as a parameter
->monthly();
我想执行以下操作:
$schedule
->command("report", [ "--email" => "[email protected]" ]) //My command which accepts the email as a parameter
->monthlyOn(1)
->when(function() {
if (in_array(Carbon::now()->dayOfWeek,[Carbon::SATURDAY,Carbon::SUNDAY])) {
return false;
}
return true;
});
$schedule
->command("report", [ "--email" => "[email protected]" ]) //My command which accepts the email as a parameter
->monthlyOn(2)
->when(function() {
if (Carbon::now()->dayOfWeek == Carbon::MONDAY) {
return true; //1st was in the weekend
}
return false;
});
$schedule
->command("report", [ "--email" => "[email protected]" ]) //My command which accepts the email as a parameter
->monthlyOn(3)
->when(function() {
if (Carbon::now()->dayOfWeek == Carbon::MONDAY) {
return true; //1st and 2nd was in the weekend
}
return false;
});
然而,这看起来像一个很奇怪的东西,为简单的东西做那样。
所以我的问题:
- 如果
when
条件失败,没有任务再次得到直到成功尝试? (假设这是一个不确定的但不确定的) - 在本月的第一个工作日是否有更简单的方法来运行任务?
运行一个cron作业,然后在cron脚本中确保day = Monday来显示它是不是更简单?因此,cron会在每个月的第一天运行,但在星期一显示? – Option
@Option问题是,当cron完成时,它会发送一封电子邮件。我不知道如何延迟发送电子邮件直到周一在cronjob内。除非你的意思是我应该每天安排它,但也要检查它是否是cronjob本月的第一个工作日? – apokryfos
https://superuser.com/questions/428807/run-a-cron-job-on-the-first-monday-of-every-month希望这会有所帮助,因为它基本上在做你想要的东西 – Option