Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled jobs: add status message if cron not running #17819

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions CRM/Admin/Page/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,37 @@ public function run() {
* Browse all jobs.
*/
public function browse() {
// check if non-prod mode is enabled.
if (CRM_Core_Config::environment() != 'Production') {
// Check if cron is actually running.
if (CRM_Core_Config::environment() == 'Production') {
$statusPreference = new CRM_Core_DAO_StatusPreference();
$statusPreference->domain_id = CRM_Core_Config::domainID();
$statusPreference->name = 'checkLastCron';
if (!$statusPreference->find(TRUE)
|| empty($statusPreference->check_info)
|| $statusPreference->prefs === 'new') {
// Cron has never run.
CRM_Core_Session::setStatus(
ts('A cron job is required to execute scheduled jobs automatically. It appears that this has never happened on this site. <a href="%1" target="_blank">Learn how to set up the cron job.</a>', [
1 => CRM_Utils_System::docURL2('sysadmin/setup/jobs', TRUE),
]),
ts('Cron not running'),
'warning',
['expires' => 0]
);
}
elseif ($statusPreference->check_info < $now - 3600) {
CRM_Core_Session::setStatus(
ts('A cron job is required to execute scheduled jobs automatically. It appears that there may be a problem with cron execution: it last ran at %1. <a href="%2" target="_blank">Learn how to set up the cron job.</a>', [
1 => CRM_Utils_Date::customFormat(date('c', $statusPreference->check_info)),
2 => CRM_Utils_System::docURL2('sysadmin/setup/jobs', TRUE),
]),
ts('Cron not running'),
'warning',
['expires' => 0]
);
}
}
else {
CRM_Core_Session::setStatus(ts('Execution of scheduled jobs has been turned off by default since this is a non-production environment. You can override this for particular jobs by adding runInNonProductionEnvironment=TRUE as a parameter.'), ts("Non-production Environment"), "warning", array('expires' => 0));
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static function handle() {
// interface can be disabled in more change to the configuration file.
// first check for civicrm site key
if (!CRM_Utils_System::authenticateKey(FALSE)) {
$docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", TRUE, NULL, NULL, NULL, "wiki");
$docLink = CRM_Utils_System::docURL2('sysadmin/setup/jobs', TRUE);
$key = $requestParams['key'] ?? NULL;
if (empty($key)) {
return self::error("FATAL: mandatory param 'key' missing. More info at: " . $docLink);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public static function authenticateKey($abort = TRUE) {
// also make sure the key is sent and is valid
$key = trim(CRM_Utils_Array::value('key', $_REQUEST));

$docAdd = "More info at:" . CRM_Utils_System::docURL2("Managing Scheduled Jobs", TRUE, NULL, NULL, NULL, "wiki");
$docAdd = "More info at:" . CRM_Utils_System::docURL2('sysadmin/setup/jobs', TRUE);

if (!$key) {
return self::authenticateAbort(
Expand Down