mirror of
https://github.com/itflow-org/itflow
synced 2026-12-04 01:59:00 +00:00
Cron leaves alone the jobs with nothing to do on an install: a job can declare not_in_use in includes/cron_jobs.php, the same check its script stops on, and cron.php skips it before its lock and claim unless it is asked to Run Now, registering its row the first time (cronJobRegister()); checks for AI Triage, Text Messages, RMM Sync, RMM Alerts, the Ticket Email Parser, Mail Queue, Payment Provider Fees, Update Check, Manager Check-in and Managed Instances; AI Triage no longer runs with triage off or no AI model (aiTriageNotInUse()); Maintenance > Cron shows them as Not in use with the reason, Cron Watch doesn't expect them to run, and CONTRIBUTING.md has the rule; 26.12.5 changelog
This commit is contained in:
@@ -29,6 +29,14 @@
|
||||
* until somebody turns it on in Maintenance > Cron. Used for work an install should opt into
|
||||
* rather than inherit from an upgrade, like the backup job filling a disk overnight.
|
||||
*
|
||||
* 'not_in_use' => function () { ... } says why the job has nothing to do on this install - its
|
||||
* feature is off or not set up - or '' when it has (cronJobNotInUse()). The dispatcher doesn't run
|
||||
* such a job at all: no lock, no claim, no script loaded and nothing written every minute, until
|
||||
* the answer changes - a Run Now still runs it. Maintenance > Cron shows it as Not in use with the
|
||||
* reason, and Cron Watch doesn't expect it to run. Make it the same check the job's script stops
|
||||
* on, cheap and offline (the database, never the network), so nothing the job would have done is
|
||||
* left undone.
|
||||
*
|
||||
* 'interval_safe' => false marks a job whose work repeats if the day repeats - nightly's
|
||||
* late fees and overdue reminders fire again on a second run of the same day. Maintenance >
|
||||
* Cron only offers the daily schedule for such a job, and the dispatcher refuses to run
|
||||
@@ -73,6 +81,9 @@ function cronJobRegistry(): array
|
||||
'description' => 'For an ITFlow managed by another (Admin > Managed By): reports how it is doing and takes what its manager sets. Stops straight away when it isn\'t managed.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
return managedIsManaged() ? '' : 'Not managed by another ITFlow';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'mail_queue',
|
||||
@@ -82,6 +93,13 @@ function cronJobRegistry(): array
|
||||
'description' => 'Sends everything ITFlow has queued - invoices, quotes, ticket replies, notifications.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
// Development mode with no test inbox still cancels what's queued (cron/mail_queue.php)
|
||||
if (trim((string) (cronJobSettings()['config_smtp_provider'] ?? '')) === '' && !(devModeOn() && devModeMailTo() === '')) {
|
||||
return 'No mail server is set up to send through - Admin > Settings > Mail';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'sms_queue',
|
||||
@@ -91,6 +109,9 @@ function cronJobRegistry(): array
|
||||
'description' => 'Sends the texts waiting to go, a second apart, texts reminders of visits and calls coming up, and tidies the text log - once texting is set up in Admin > Text Messaging.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
return smsProvider() ? '' : "Texting isn't set up - Admin > Text Messaging";
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'rmm_sync',
|
||||
@@ -100,6 +121,14 @@ function cronJobRegistry(): array
|
||||
'description' => 'Brings in the devices of the RMM clients linked in Admin > RMM Providers, and of the network platforms\' sites linked in Admin > Network Platforms, as assets, and keeps up whether each is online - once one is set up there.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 15,
|
||||
'not_in_use' => function () {
|
||||
foreach (rmmProviders(true) as $provider) {
|
||||
if (rmmProviderUsable($provider)) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return 'No RMM provider or network platform is set up and on';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'rmm_alerts',
|
||||
@@ -109,6 +138,17 @@ function cronJobRegistry(): array
|
||||
'description' => 'Opens a ticket for each new alert from an RMM provider whose alerts open tickets in Admin > RMM Providers, or for each device that goes offline on a network platform in Admin > Network Platforms, and resolves it when the alert clears.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
if (intval(cronJobSettings()['config_module_enable_ticketing'] ?? 0) === 0) {
|
||||
return 'Ticketing is turned off';
|
||||
}
|
||||
foreach (rmmProviders(true) as $provider) {
|
||||
if (rmmAlertsOn($provider)) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return 'No RMM provider or network platform opens tickets for its alerts';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'ticket_email_parser',
|
||||
@@ -118,6 +158,16 @@ function cronJobRegistry(): array
|
||||
'description' => 'Reads the support mailbox and turns incoming mail into tickets and replies.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
$settings = cronJobSettings();
|
||||
if (intval($settings['config_ticket_email_parse'] ?? 0) === 0) {
|
||||
return 'Email to ticket is off in Settings > Tickets';
|
||||
}
|
||||
if (trim((string) ($settings['config_imap_provider'] ?? '')) === '') {
|
||||
return 'No mailbox is set up to read - Admin > Settings > Mail';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'ticket_sla',
|
||||
@@ -145,6 +195,9 @@ function cronJobRegistry(): array
|
||||
'description' => 'Gives new tickets from email, the portal and the API a category and priority by AI, when Settings > Tickets says to. Up to 5 a run.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 1,
|
||||
'not_in_use' => function () {
|
||||
return aiTriageNotInUse();
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'managed_instances',
|
||||
@@ -154,6 +207,15 @@ function cronJobRegistry(): array
|
||||
'description' => 'For an ITFlow that manages others (Admin > Managed Instances): notifies when one stops checking in, opens tickets for their problems when set to, and closes requests that were never answered.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 5,
|
||||
'not_in_use' => function () {
|
||||
global $mysqli;
|
||||
if (!settingsColumnExists($mysqli, 'config_manager_keys')) {
|
||||
return '';
|
||||
}
|
||||
$connected = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM managed_instances
|
||||
WHERE managed_instance_archived_at IS NULL AND managed_instance_secret_hash IS NOT NULL"))[0] ?? 0);
|
||||
return $connected ? '' : 'No instances connected';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'payment_provider_fees',
|
||||
@@ -163,6 +225,10 @@ function cronJobRegistry(): array
|
||||
'description' => 'Records what Stripe charged on each card payment as an expense, once Stripe has settled it - while Admin > Payment Providers records its fees.',
|
||||
'schedule' => 'Interval',
|
||||
'interval_minutes' => 15,
|
||||
'not_in_use' => function () {
|
||||
global $mysqli;
|
||||
return mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM payment_providers WHERE payment_provider_name = 'Stripe' LIMIT 1")) ? '' : 'No Stripe payment provider - Admin > Payment Providers';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'ticket_pictures',
|
||||
@@ -220,6 +286,9 @@ function cronJobRegistry(): array
|
||||
'description' => 'Asks the git remote whether a newer release exists and stores the answer for Maintenance > Update.',
|
||||
'schedule' => 'Daily',
|
||||
'daily_at' => '02:30',
|
||||
'not_in_use' => function () {
|
||||
return file_exists(dirname(__DIR__) . '/.git') ? '' : 'Not a git checkout - there is no remote to check against';
|
||||
},
|
||||
],
|
||||
[
|
||||
'name' => 'cron_watch',
|
||||
@@ -328,3 +397,35 @@ function cronJobNextRun(array $row): ?string
|
||||
|
||||
return date('Y-m-d H:i:s', max($next, time()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Why a job has nothing to do here - its 'not_in_use' answer - or '' when it has, or has no such
|
||||
* check. A check that throws (a table the update hasn't made yet, say) counts as in use: the job runs
|
||||
* and says for itself what's wrong.
|
||||
*/
|
||||
function cronJobNotInUse(array $job): string
|
||||
{
|
||||
if (!isset($job['not_in_use']) || !is_callable($job['not_in_use'])) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
return trim((string) ($job['not_in_use'])());
|
||||
} catch (Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The settings the 'not_in_use' checks read, once a request - the dispatcher asks every minute, and
|
||||
* cron reads none of config.php's globals for them.
|
||||
*/
|
||||
function cronJobSettings(): array
|
||||
{
|
||||
global $mysqli;
|
||||
static $settings = null;
|
||||
if ($settings === null) {
|
||||
$settings = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_smtp_provider, config_imap_provider, config_ticket_email_parse,
|
||||
config_module_enable_ticketing FROM settings WHERE company_id = 1")) ?: [];
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user