Skip to content

Commit

Permalink
Added detection of external triggers of the scheduler (#3726)
Browse files Browse the repository at this point in the history
Added extension to the isCrontabSetup method to detect external triggers of the scheduler, so that in the admin interface the error message is hidden when the scheduler is called by an external trigger.
  • Loading branch information
codebude authored Oct 24, 2023
1 parent 80ce87e commit db3e39f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion system/src/Grav/Common/Scheduler/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public function run(DateTime $runTime = null, $force = false)

// Store states
$this->saveJobStates();

// Store run date
file_put_contents("logs/lastcron.run", (new DateTime("now"))->format("Y-m-d H:i:s"), LOCK_EX);
}

/**
Expand Down Expand Up @@ -291,7 +294,7 @@ public function getSchedulerCommand($php = null)
}

/**
* Helper to determine if cron job is setup
* Helper to determine if cron-like job is setup
* 0 - Crontab Not found
* 1 - Crontab Found
* 2 - Error
Expand All @@ -300,6 +303,13 @@ public function getSchedulerCommand($php = null)
*/
public function isCrontabSetup()
{
// Check for external triggers
$last_run = @file_get_contents("logs/lastcron.run");
if (time() - strtotime($last_run) < 120){
return 1;
}

// No external triggers found, so do legacy cron checks
$process = new Process(['crontab', '-l']);
$process->run();

Expand Down

0 comments on commit db3e39f

Please sign in to comment.