Commit 11734cf6 authored by Robert Lyon's avatar Robert Lyon
Browse files

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 847f49ef
...@@ -41,6 +41,7 @@ $string['forumtopic'] = 'Forum topic'; ...@@ -41,6 +41,7 @@ $string['forumtopic'] = 'Forum topic';
$string['Group'] = 'Group'; $string['Group'] = 'Group';
$string['host'] = 'Host'; $string['host'] = 'Host';
$string['hostdescription'] = 'Hostname of the Elasticsearch server. Default is 127.0.0.1.'; $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['indexname'] = 'Index name';
$string['indexnamedescription'] = 'Name of the Elasticsearch index. Default is mahara.'; $string['indexnamedescription'] = 'Name of the Elasticsearch index. Default is mahara.';
$string['license'] = 'License'; $string['license'] = 'License';
......
...@@ -336,6 +336,13 @@ class PluginSearchElasticsearch extends PluginSearch { ...@@ -336,6 +336,13 @@ class PluginSearchElasticsearch extends PluginSearch {
return $config; return $config;
} }
public function validate_config_options($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 function save_config_options($values) { public function save_config_options($values) {
set_config_plugin('search', 'elasticsearch', 'cronlimit', $values['cronlimit']); set_config_plugin('search', 'elasticsearch', 'cronlimit', $values['cronlimit']);
...@@ -364,9 +371,16 @@ class PluginSearchElasticsearch extends PluginSearch { ...@@ -364,9 +371,16 @@ class PluginSearchElasticsearch extends PluginSearch {
// If they chose to reset all the indexes, do that. // If they chose to reset all the indexes, do that.
if (isset($values['allreset'])) { 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(); self::reset_all_searchtypes();
// Send the first batch of records to the elasticsearch server now, for instant gratification // Send the first batch of records to the elasticsearch server now, for instant gratification
self::index_queued_items(); 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 // TODO: Make single-searchtype reset work properly. For now we'll just comment this out in hopes
// it will aid a future developer. // 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