Skip to content

Commit 4c283a2

Browse files
committed
Fix: Support data type change of columns ts_last_attempt and ts_last_error from timestamp to bigint
1 parent 63dac34 commit 4c283a2

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

library/Director/Objects/DirectorJob.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Icinga\Module\Director\Objects;
44

55
use Icinga\Exception\NotFoundError;
6+
use Icinga\Module\Director\Daemon\DaemonUtil;
67
use Icinga\Module\Director\Daemon\Logger;
78
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
89
use Icinga\Module\Director\Db;
@@ -84,15 +85,16 @@ public function getInstance()
8485
public function run()
8586
{
8687
$job = $this->getInstance();
87-
$this->set('ts_last_attempt', date('Y-m-d H:i:s'));
88+
$currentTimestamp = DaemonUtil::timestampWithMilliseconds();
89+
$this->set('ts_last_attempt', $currentTimestamp);
8890

8991
try {
9092
$job->run();
9193
$this->set('last_attempt_succeeded', 'y');
9294
$success = true;
9395
} catch (Exception $e) {
9496
Logger::error($e->getMessage());
95-
$this->set('ts_last_error', date('Y-m-d H:i:s'));
97+
$this->set('ts_last_error', $currentTimestamp);
9698
$this->set('last_error_message', $e->getMessage());
9799
$this->set('last_attempt_succeeded', 'n');
98100
$success = false;
@@ -127,8 +129,8 @@ public function isOverdue()
127129
}
128130

129131
return (
130-
strtotime($this->get('ts_last_attempt')) + $this->get('run_interval') * 2
131-
) < time();
132+
$this->get('ts_last_attempt') + $this->get('run_interval') * 2 * 1000
133+
) < DaemonUtil::timestampWithMilliseconds();
132134
}
133135

134136
public function hasBeenDisabled()
@@ -145,7 +147,9 @@ public function isPending()
145147
return $this->isWithinTimeperiod();
146148
}
147149

148-
if (strtotime($this->get('ts_last_attempt')) + $this->get('run_interval') < time()) {
150+
if (
151+
$this->get('ts_last_attempt') + $this->get('run_interval') * 1000 < DaemonUtil::timestampWithMilliseconds()
152+
) {
149153
return $this->isWithinTimeperiod();
150154
}
151155

library/Director/Web/Table/JobTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use gipfl\IcingaWeb2\Link;
66
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
7+
use Icinga\Module\Director\Daemon\DaemonUtil;
78

89
class JobTable extends ZfQueryBasedTable
910
{
@@ -37,11 +38,11 @@ public function renderRow($row)
3738

3839
protected function getJobClasses($row)
3940
{
40-
if ($row->unixts_last_attempt === null) {
41+
if ($row->ts_last_attempt === null) {
4142
return 'pending';
4243
}
4344

44-
if ($row->unixts_last_attempt + $row->run_interval < time()) {
45+
if ($row->ts_last_attempt + $row->run_interval * 1000 < DaemonUtil::timestampWithMilliseconds()) {
4546
return 'pending';
4647
}
4748

@@ -73,7 +74,6 @@ public function prepareQuery()
7374
'run_interval' => 'j.run_interval',
7475
'last_attempt_succeeded' => 'j.last_attempt_succeeded',
7576
'ts_last_attempt' => 'j.ts_last_attempt',
76-
'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)',
7777
'ts_last_error' => 'j.ts_last_error',
7878
'last_error_message' => 'j.last_error_message',
7979
]

library/Director/Web/Widget/JobDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(DirectorJob $job)
4545

4646
$tsLastAttempt = $job->get('ts_last_attempt');
4747
if ($tsLastAttempt) {
48-
$ts = \strtotime($tsLastAttempt);
48+
$ts = $tsLastAttempt / 1000;
4949
$timeAgo = Html::tag('span', [
5050
'class' => 'time-ago',
5151
'title' => DateFormatter::formatDateTime($ts)

schema/mysql-migrations/upgrade_189.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ ALTER TABLE director_job
1414

1515
INSERT INTO director_schema_migration
1616
(schema_version, migration_time)
17-
VALUES (189, NOW());
17+
VALUES (189, NOW());

0 commit comments

Comments
 (0)