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