Commit 358070bd authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1731067: drop elasticsearch triggers for some cron jobs

behatnotneeded

Change-Id: I63b953b3a31f38c96f66d602e67622b62cdb0b01
parent 95aada8c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -55,6 +55,15 @@ if (!is_writable(get_config('dataroot'))) {
    log_warn("Unable to write to dataroot directory.");
}

// cron jobs (callfunction as in 'cron' table)
// that need to drop the elasticsearch triggers
$jobsneeddroptriggers = array(
    'recalculate_quota',
    'cron_site_data_daily',
    'user_login_tries_to_zero',
    'interaction_forum_new_post',
);

// for each plugin type
foreach (plugin_types() as $plugintype) {

@@ -97,6 +106,11 @@ foreach (plugin_types() as $plugintype) {

            safe_require($plugintype, $job->plugin, 'lib.php', 'require_once');

            $droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
            if ($droptriggers) {
                drop_elasticsearch_triggers();
            }

            try {
                call_static_method($classname, $job->callfunction);
            }
@@ -107,6 +121,10 @@ foreach (plugin_types() as $plugintype) {
                // Don't call handle_exception; try to update next run time and free the lock
            }

            if ($droptriggers) {
                create_elasticsearch_triggers();
            }

            $nextrun = cron_next_run_time($start, (array)$job);

            // update next run time
@@ -159,6 +177,11 @@ if ($jobs) {

        $function = $job->callfunction;

        $droptriggers = in_array($job->callfunction, $jobsneeddroptriggers);
        if ($droptriggers) {
            drop_elasticsearch_triggers();
        }

        try {
            $function();
        }
@@ -169,6 +192,10 @@ if ($jobs) {
            // Don't call handle_exception; try to update next run time and free the lock
        }

        if ($droptriggers) {
            create_elasticsearch_triggers();
        }

        $nextrun = cron_next_run_time($start, (array)$job);

        // update next run time