1

Laravel 5.8.33

I run 2 schedules, one every 5 minutes and one once a month. The five minues schedule runs perfectly using everyFiveMinutes(). But the monthly schedule monthly() never runs. I also tried monthlyOn(1, '00:15') but still the issue remains.

If I swap out monthly() for everyFiveMinutes() it works no problem.

There are no errors in the log file, it simply doesn't run. Has anybody else had this issue? Is there an alternative request to monthly()?

    $logfilename = 'cron_'. now()->format('Y_m_d') . '.txt'; 

    //Push Notification check - RUNS EVERY FIVE MINUTES
    $schedule->exec('env -i /usr/local/bin/php72 -f /www/xxxx-xxxx.com/artisan command:pushmessages')->everyFiveMinutes()->appendOutputTo(public_path().'/logs/'.$logfilename);

    //End of month stats archive - NEVER RUNS
    $schedule->exec('env -i /usr/local/bin/php72 -f /www/xxxx-xxxx.com/artisan command:archivestats')->monthly()->appendOutputTo(public_path().'/logs/'.$logfilename);
Delmontee
  • 1,898
  • 2
  • 26
  • 44
  • I can't think of a reason not to work, but I can suggest using a condition and checking the date to be the first of the month: `->daily()->when(function () { return date('d') == '01'; });` – thefallen May 18 '20 at 08:23
  • Are you absolutely sure it does not run? `monthly()` will run at midnight on the first of the month - is there some date/time/month-related code or test in your script which might fail or not pass at that time or something like that? Is there an execution flow for the script to run and not generate any output or errors? Add some logging at the start of the script that will be executed no matter what. – Don't Panic May 20 '20 at 01:10
  • See eg [this question](https://stackoverflow.com/q/61060132/6089612) - OP was convinced their job was not running, but it was simply running without error checking and did not generate output. – Don't Panic May 20 '20 at 01:16

2 Answers2

0

I know it's late answer but this could be helpful. it's strange as the syntax is correct and I can think of only 1 reason which is the command itself could you share archivestats command code ?

Here are some steps to follow:

  1. run this command:

$schedule->exec('env -i /usr/local/bin/php72 -f /www/xxxx-xxxx.com/artisan command:pushmessages')->monthly()->appendOutputTo(public_path().'/logs/'.$logfilename);

if it works then for sure the problem is in the archivestats command.

  1. create a cron task (from GUI or from the terminal for example but not from laravel) that will run on the server monthly ... checkout this link and this link as well.

if you could share the results of the above steps that will help in detecting what's wrong.

Mahmood Ahmad
  • 452
  • 4
  • 11
  • Thanks - sorry this is incredibly late - the monthly() schedule doesn't seem to run at all. If I run my achivestats on everyfiveminutes() then it processes with no problem. So monthly() isn't running :S – Delmontee Jan 26 '21 at 14:12
0

If your first command takes over a minute to run, your second command might never see 00:00 in order to run monthly.

Try changing the order of the jobs so that the monthly task gets opportunity to run at midnight.

Snapey
  • 3,604
  • 1
  • 21
  • 19
  • the command only takes a couple of seconds – Delmontee Jan 25 '21 at 15:48
  • Still an issue? – Snapey Jan 25 '21 at 20:57
  • Sadly. I've been ignoring it recently. – Delmontee Jan 26 '21 at 14:10
  • It shouldn't make a difference, but have you tried the command format? `$schedule->command('archivestats')->monthly()->appendOutputTo(public_path().'/logs/'.$logfilename);` Maybe not relevant, but having your log files in the public folder is concerning – Snapey Jan 26 '21 at 20:15
  • Thanks, I tried this but using everyfiveminutes to start with. I get "unexpected character in input: '\' (ASCII=92) state=1 in /kunden/xxxxxx_xx/webseiten/websitename.com/artisan on line 33

    Parse error: syntax error, unexpected T_STRING in /kunden/xxxxxx_xx/webseiten/websitename.com/artisan on line 33
    "
    – Delmontee Jan 27 '21 at 08:37
  • -- the site is hosted on domain factory so we have to run cron jobs a slightly diffferent way to most. And when it run the monthly cron as an everyfiveminutes cron using the domain factory method it works. Just not for monthly. – Delmontee Jan 27 '21 at 08:58
  • I'm going to try running once a week, and if day of month <=7 then it will perform the response. Will update you if it works. – Delmontee Jan 27 '21 at 09:08