Skip to content

Commit

Permalink
Fixes problem where species_alerts where not getting sent because the…
Browse files Browse the repository at this point in the history
… location_ids field wasn't being filled in quickly enough for occdelta.
  • Loading branch information
Andrew van Breda committed Nov 11, 2019
1 parent 95ec9fd commit 82cc4e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
*
* @var string
*/
$config['version'] = '2.37.0';
$config['version'] = '2.37.1';

/**
* Version release date.
*
* @var string
*/
$config['release_date'] = '2019-11-07';
$config['release_date'] = '2019-11-11';

/**
* Link to the code repository downloads page.
Expand Down
21 changes: 15 additions & 6 deletions application/controllers/scheduled_tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,16 @@ private function runScheduledPlugins($system, array $scheduledPlugins) {
// take 1 second off current time to use as the end of the scanned time period. Avoids possibilities of records
// being lost half way through the current second.
$t = time() - 1;
$currentTime = date("Y-m-d H:i:s", $t);
$maxTime = date("Y-m-d H:i:s", $t);
$latestUnprocessed = $this->db
->select("min(created_on) - '1 second'::interval as maxtime")
->from('work_queue')
->in('task', ['task_spatial_index_builder_sample', ' task_spatial_index_builder_occurrence'])
->where('claimed_by', NULL)
->get()->current();
if ($latestUnprocessed->maxtime !== NULL) {
$maxTime = $latestUnprocessed->maxtime;
}
$plugins = $this->getScheduledPlugins();
// Load the plugins and last run date info from the system table. Any not run before will start from the current timepoint.
// We need this to be sorted, so we can process the list of changed records for each group of plugins with the same timestamp together.
Expand All @@ -686,12 +695,12 @@ private function runScheduledPlugins($system, array $scheduledPlugins) {
$sortedPlugins = array();
foreach ($pluginsFromDb as $plugin) {
$sortedPlugins[$plugin->name] = $plugin->last_scheduled_task_check === NULL
? $currentTime : $plugin->last_scheduled_task_check;
? $maxTime : $plugin->last_scheduled_task_check;
}
// Any new plugins not run before should also be included in the list.
foreach ($plugins as $plugin) {
if (!isset($sortedPlugins[$plugin])) {
$sortedPlugins[$plugin] = $currentTime;
$sortedPlugins[$plugin] = $maxTime;
}
}
// Make sure data_cleaner runs before auto_verify module.
Expand Down Expand Up @@ -720,7 +729,7 @@ private function runScheduledPlugins($system, array $scheduledPlugins) {
if (in_array('all_modules', $scheduledPlugins) || in_array($plugin, $scheduledPlugins)) {
require_once MODPATH . "$plugin/plugins/$plugin.php";
$this->loadPluginMetadata($plugin);
$this->loadOccurrencesDelta($timestamp, $currentTime);
$this->loadOccurrencesDelta($timestamp, $maxTime);
// Call the plugin, only if there are records to process, or it doesn't
// care.
if (!$this->pluginMetadata['requires_occurrences_delta']
Expand All @@ -729,7 +738,7 @@ private function runScheduledPlugins($system, array $scheduledPlugins) {
echo "<h2>Running $plugin</h2>";
echo "<p>Last run at $timestamp</p>";
$tm = microtime(TRUE);
call_user_func($plugin . '_scheduled_task', $timestamp, $this->db, $currentTime);
call_user_func($plugin . '_scheduled_task', $timestamp, $this->db, $maxTime);
// Log plugins which take more than 5 seconds.
$took = microtime(TRUE) - $tm;
if ($took > 5) {
Expand All @@ -744,7 +753,7 @@ private function runScheduledPlugins($system, array $scheduledPlugins) {
}
// Mark the time of the last scheduled task check so we can get the
// correct list of updates next time.
$timestamp = $this->pluginMetadata['requires_occurrences_delta'] ? $this->occdeltaEndTimestamp : $currentTime;
$timestamp = $this->pluginMetadata['requires_occurrences_delta'] ? $this->occdeltaEndTimestamp : $maxTime;
if (!$this->db->update('system', array('last_scheduled_task_check' => $timestamp), array('name' => $plugin))->count())
$this->db->insert('system', array(
'version' => '0.1.0',
Expand Down

0 comments on commit 82cc4e4

Please sign in to comment.