【问题标题】:How can I run this cron?我怎样才能运行这个 cron?
【发布时间】:2020-10-22 01:41:43
【问题描述】:

我有一些计划用于在某些时间清理数据库,但我想使用 cron 来运行这些时间,但是当我尝试在 Windows 计划中运行它们时,我收到以下错误:

 6 is not a valid position

      at C:\laragon\www\Sis\vendor\dragonmantank\cron-expression\src\Cron\FieldFactory.php:46
        42|                 case 4:
        43|                     $this->fields[$position] = new DayOfWeekField();
        44|                     break;
        45|                 default:
      > 46|                     throw new InvalidArgumentException(
        47|                         ($position + 1) . ' is not a valid position'
        48|                     );
        49|             }
        50|         }
    
      1   C:\laragon\www\Sis\vendor\dragonmantank\cron-expression\src\Cron\CronExpression.php:154
          Cron\FieldFactory::getField()
    
      2   C:\laragon\www\Sis\vendor\dragonmantank\cron-expression\src\Cron\CronExpression.php:137
          Cron\CronExpression::setPart("*")

而且我对 crons 没有太多经验,据我所知,它应该需要 6 个星号,并且您指定了分钟、小时、天、月,我该如何解决?

这是代码:

 protected function schedule(Schedule $schedule)
    {
     $schedule->command('S:LA')->cron('0 23 4 1 * *');
    $schedule->command('S:LC')->cron('0 23 4 2 * *');
    $schedule->command('S:LC')->cron('0 23 4 6 * *');
    $schedule->command('S:LC')->cron('0 23 4 10 * *');
    $schedule->command('S:LD')->dailyAt('00:00');
    $schedule->command('S:LM')->monthlyOn(4, '23:00');
    $schedule->command('S:LS')->mondays()->at('23:00');
    $schedule->command('S:LSM')->cron('0 23 4 6 * *');
    $schedule->command('S:LSM')->cron('0 23 4 1 * *');
    $schedule->command('S:LT')->cron('0 23 4 1 * *');
    $schedule->command('S:LT')->cron('0 23 4 3 * *');
    $schedule->command('S:LT')->cron('0 23 4 6 * *');
    $schedule->command('S:LT')->cron('0 23 4 9 * *');
    $schedule->command('S:LT')->cron('0 23 4 12 * *');
    
  }

【问题讨论】:

  • This应该回答你的问题,你可以测试你的表达here
  • 5 个星号,就是我想说的。

标签: laravel cron scheduled-tasks


【解决方案1】:
->cron('* * * * *');    Run the task on a custom Cron schedule
->everyMinute();    Run the task every minute
->everyTwoMinutes();    Run the task every two minutes
->everyThreeMinutes();  Run the task every three minutes
->everyFourMinutes();   Run the task every four minutes
->everyFiveMinutes();   Run the task every five minutes
->everyTenMinutes();    Run the task every ten minutes
->everyFifteenMinutes();    Run the task every fifteen minutes
->everyThirtyMinutes(); Run the task every thirty minutes
->hourly(); Run the task every hour
->hourlyAt(17); Run the task every hour at 17 minutes past the hour
->everyTwoHours();  Run the task every two hours
->everyThreeHours();    Run the task every three hours
->everyFourHours(); Run the task every four hours
->everySixHours();  Run the task every six hours
->daily();  Run the task every day at midnight
->dailyAt('13:00'); Run the task every day at 13:00
->twiceDaily(1, 13);    Run the task daily at 1:00 & 13:00
->weekly(); Run the task every sunday at 00:00
->weeklyOn(1, '8:00');  Run the task every week on Monday at 8:00
->monthly();    Run the task on the first day of every month at 00:00
->monthlyOn(4, '15:00');    Run the task every month on the 4th at 15:00
->quarterly();  Run the task on the first day of every quarter at 00:00
->yearly(); Run the task on the first day of every year at 00:00
->timezone('America/New_York'); Set the timezone

【讨论】:

  • 解释你的答案
  • 这些是默认的 laravel cron 命令。第一个,->cron('* * * * *');仅显示 5 个 cron 值。您在示例中的命令有 6 个字段。
猜你喜欢
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多