自定义日Laravel的任务计划

时间:2019-10-07 15:06:51

标签: laravel cron scheduled-tasks cron-task

这几天我想很好地完成这项工作,我可以将at()与when()一起使用吗????

$schedule->command('mycommand')->when(function () {
            $day = Carbon::today()->day;
            if($day == 3 || $day == 5 || $day == 7 || $day == 22) {
                return true;
            } else {
                return false;
            }
        })->at('17:00');

2 个答案:

答案 0 :(得分:4)

您可以使用这种方式:

SSLSocketFactory getSSLSocketFactory() {
    char[] allPassword = keyStorePassword.toCharArray();
    SSLContext sslContext = null;
    try {
        sslContext = SSLContextBuilder
            .create()
            .setKeyStoreType(keyStoreType)
            .loadKeyMaterial(ResourceUtils.getFile(keyStore), allPassword, allPassword)
            .build();
    } catch (Exception e) { /* *** */ }
    return sslContext.getSocketFactory();
}

或更简单的方法,使用cron:

$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');

答案 1 :(得分:2)

您可以在特定日期重复多个月度运行

$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');

希望这会有所帮助