簡體   English   中英

Laravel 禁用計划作業

[英]Laravel disable a scheduled job

我有一個包含多個預定作業的實時 PHP/Laravel 項目,客戶要求禁用其中一個作業,有沒有辦法通過命令行禁用其中一個預定作業?

當然,我可以注釋掉 console\kernel.php 中的代碼,它注冊了任務,但這只是暫時的,我不想只為這一項任務進行代碼更改和發布。

+-------------+-----------------------------------------------+
| Cron        | Command                                       |
+-------------+-----------------------------------------------+
| 0 23 * * 7  | 'artisan' export:blahblah                  |
| 0 1 5 * *   | 'artisan' invoices:somejob          | <---- i want to disable just this one job
| 30 1 * * *  | 'artisan' invoices:blahblahblah         |

您可以配置一個全局變量或數據庫標志,每次在運行命令邏輯之前都會檢查它。

例如:

<?php

class InvoicesCommand {
...

// handles invoices:somejob command
public function handle() {
    // get command flag (can be set from .env too, or however you want)
    $invoicesCommandFlag = Configuration::where('key', 'invoices_command_flag')->firstOrFail();

    // check if command is "enabled"
    if (!$invoicesCommandFlag->value) {
        \Log::debug('Command disabled. Aborting.');
        return;
    }

    // do stuff...
}
...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM