Commit 6722bcfa authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Stopping the elasticsearch cron running at same time as reset index

Bug #1422232

Change-Id: Ia8fd7d074db3be027e1318a07d062a9ed1bb2ad8
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent fb3715c6
......@@ -42,6 +42,7 @@ $string['forumtopic'] = 'Forum topic';
$string['Group'] = 'Group';
$string['host'] = 'Host';
$string['hostdescription'] = 'Hostname of the Elasticsearch server. Default is 127.0.0.1.';
$string['indexingrunning'] = 'Indexing cron job is running. Please try again in a few minutes.';
$string['indexname'] = 'Index name';
$string['indexnamedescription'] = 'Name of the Elasticsearch index. Default is mahara.';
$string['license'] = 'License';
......
......@@ -336,6 +336,13 @@ class PluginSearchElasticsearch extends PluginSearch {
return $config;
}
public static function validate_config_options(Pieform $form, $values) {
// First check that there isn't an elasticsearch cron indexing the site
if (get_record('config', 'field', '_cron_lock_search_elasticsearch_cron')) {
$form->set_error(null, get_string('indexingrunning', 'search.elasticsearch'));
}
}
public static function save_config_options(Pieform $form, $values) {
set_config_plugin('search', 'elasticsearch', 'cronlimit', $values['cronlimit']);
......@@ -364,9 +371,16 @@ class PluginSearchElasticsearch extends PluginSearch {
// If they chose to reset all the indexes, do that.
if (isset($values['allreset'])) {
// set the cron lock before beginning re index to stop the cron indexing at same time
$start = time();
insert_record('config', (object) array('field' => '_cron_lock_search_elasticsearch_cron', 'value' => $start));
self::reset_all_searchtypes();
// Send the first batch of records to the elasticsearch server now, for instant gratification
self::index_queued_items();
// free the cron lock
delete_records('config', 'field', '_cron_lock_search_elasticsearch_cron', 'value', $start);
}
// TODO: Make single-searchtype reset work properly. For now we'll just comment this out in hopes
// it will aid a future developer.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment