Fix: Support data type change of columns ts_last_attempt and ts_last_error from timestamp to bigint

This commit is contained in:
raviks789 2025-02-04 15:43:18 +01:00
parent 63dac34b0f
commit 4c283a24c8
No known key found for this signature in database
4 changed files with 14 additions and 10 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Objects; namespace Icinga\Module\Director\Objects;
use Icinga\Exception\NotFoundError; use Icinga\Exception\NotFoundError;
use Icinga\Module\Director\Daemon\DaemonUtil;
use Icinga\Module\Director\Daemon\Logger; use Icinga\Module\Director\Daemon\Logger;
use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
@ -84,7 +85,8 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
public function run() public function run()
{ {
$job = $this->getInstance(); $job = $this->getInstance();
$this->set('ts_last_attempt', date('Y-m-d H:i:s')); $currentTimestamp = DaemonUtil::timestampWithMilliseconds();
$this->set('ts_last_attempt', $currentTimestamp);
try { try {
$job->run(); $job->run();
@ -92,7 +94,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
$success = true; $success = true;
} catch (Exception $e) { } catch (Exception $e) {
Logger::error($e->getMessage()); Logger::error($e->getMessage());
$this->set('ts_last_error', date('Y-m-d H:i:s')); $this->set('ts_last_error', $currentTimestamp);
$this->set('last_error_message', $e->getMessage()); $this->set('last_error_message', $e->getMessage());
$this->set('last_attempt_succeeded', 'n'); $this->set('last_attempt_succeeded', 'n');
$success = false; $success = false;
@ -127,8 +129,8 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
} }
return ( return (
strtotime($this->get('ts_last_attempt')) + $this->get('run_interval') * 2 $this->get('ts_last_attempt') + $this->get('run_interval') * 2 * 1000
) < time(); ) < DaemonUtil::timestampWithMilliseconds();
} }
public function hasBeenDisabled() public function hasBeenDisabled()
@ -145,7 +147,9 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
return $this->isWithinTimeperiod(); return $this->isWithinTimeperiod();
} }
if (strtotime($this->get('ts_last_attempt')) + $this->get('run_interval') < time()) { if (
$this->get('ts_last_attempt') + $this->get('run_interval') * 1000 < DaemonUtil::timestampWithMilliseconds()
) {
return $this->isWithinTimeperiod(); return $this->isWithinTimeperiod();
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Web\Table;
use gipfl\IcingaWeb2\Link; use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable; use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use Icinga\Module\Director\Daemon\DaemonUtil;
class JobTable extends ZfQueryBasedTable class JobTable extends ZfQueryBasedTable
{ {
@ -37,11 +38,11 @@ class JobTable extends ZfQueryBasedTable
protected function getJobClasses($row) protected function getJobClasses($row)
{ {
if ($row->unixts_last_attempt === null) { if ($row->ts_last_attempt === null) {
return 'pending'; return 'pending';
} }
if ($row->unixts_last_attempt + $row->run_interval < time()) { if ($row->ts_last_attempt + $row->run_interval * 1000 < DaemonUtil::timestampWithMilliseconds()) {
return 'pending'; return 'pending';
} }
@ -73,7 +74,6 @@ class JobTable extends ZfQueryBasedTable
'run_interval' => 'j.run_interval', 'run_interval' => 'j.run_interval',
'last_attempt_succeeded' => 'j.last_attempt_succeeded', 'last_attempt_succeeded' => 'j.last_attempt_succeeded',
'ts_last_attempt' => 'j.ts_last_attempt', 'ts_last_attempt' => 'j.ts_last_attempt',
'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)',
'ts_last_error' => 'j.ts_last_error', 'ts_last_error' => 'j.ts_last_error',
'last_error_message' => 'j.last_error_message', 'last_error_message' => 'j.last_error_message',
] ]

View File

@ -45,7 +45,7 @@ class JobDetails extends HtmlDocument
$tsLastAttempt = $job->get('ts_last_attempt'); $tsLastAttempt = $job->get('ts_last_attempt');
if ($tsLastAttempt) { if ($tsLastAttempt) {
$ts = \strtotime($tsLastAttempt); $ts = $tsLastAttempt / 1000;
$timeAgo = Html::tag('span', [ $timeAgo = Html::tag('span', [
'class' => 'time-ago', 'class' => 'time-ago',
'title' => DateFormatter::formatDateTime($ts) 'title' => DateFormatter::formatDateTime($ts)

View File

@ -14,4 +14,4 @@ ALTER TABLE director_job
INSERT INTO director_schema_migration INSERT INTO director_schema_migration
(schema_version, migration_time) (schema_version, migration_time)
VALUES (189, NOW()); VALUES (189, NOW());