Fix: Support data type change of columns `ts_last_attempt` and `ts_last_error` from timestamp to bigint
This commit is contained in:
parent
b41564f3e9
commit
faa05d9f45
|
@ -3,6 +3,7 @@
|
|||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\Daemon\DaemonUtil;
|
||||
use Icinga\Module\Director\Daemon\Logger;
|
||||
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
||||
use Icinga\Module\Director\Db;
|
||||
|
@ -84,7 +85,8 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
|
|||
public function run()
|
||||
{
|
||||
$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 {
|
||||
$job->run();
|
||||
|
@ -92,7 +94,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
|
|||
$success = true;
|
||||
} catch (Exception $e) {
|
||||
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_attempt_succeeded', 'n');
|
||||
$success = false;
|
||||
|
@ -127,8 +129,8 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
|
|||
}
|
||||
|
||||
return (
|
||||
strtotime($this->get('ts_last_attempt')) + $this->get('run_interval') * 2
|
||||
) < time();
|
||||
$this->get('ts_last_attempt') + $this->get('run_interval') * 2 * 1000
|
||||
) < DaemonUtil::timestampWithMilliseconds();
|
||||
}
|
||||
|
||||
public function hasBeenDisabled()
|
||||
|
@ -145,7 +147,9 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Web\Table;
|
|||
|
||||
use gipfl\IcingaWeb2\Link;
|
||||
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
|
||||
use Icinga\Module\Director\Daemon\DaemonUtil;
|
||||
|
||||
class JobTable extends ZfQueryBasedTable
|
||||
{
|
||||
|
@ -37,11 +38,11 @@ class JobTable extends ZfQueryBasedTable
|
|||
|
||||
protected function getJobClasses($row)
|
||||
{
|
||||
if ($row->unixts_last_attempt === null) {
|
||||
if ($row->ts_last_attempt === null) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
if ($row->unixts_last_attempt + $row->run_interval < time()) {
|
||||
if ($row->ts_last_attempt + $row->run_interval * 1000 < DaemonUtil::timestampWithMilliseconds()) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
|
@ -73,7 +74,6 @@ class JobTable extends ZfQueryBasedTable
|
|||
'run_interval' => 'j.run_interval',
|
||||
'last_attempt_succeeded' => 'j.last_attempt_succeeded',
|
||||
'ts_last_attempt' => 'j.ts_last_attempt',
|
||||
'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)',
|
||||
'ts_last_error' => 'j.ts_last_error',
|
||||
'last_error_message' => 'j.last_error_message',
|
||||
]
|
||||
|
|
|
@ -45,7 +45,7 @@ class JobDetails extends HtmlDocument
|
|||
|
||||
$tsLastAttempt = $job->get('ts_last_attempt');
|
||||
if ($tsLastAttempt) {
|
||||
$ts = \strtotime($tsLastAttempt);
|
||||
$ts = $tsLastAttempt / 1000;
|
||||
$timeAgo = Html::tag('span', [
|
||||
'class' => 'time-ago',
|
||||
'title' => DateFormatter::formatDateTime($ts)
|
||||
|
|
Loading…
Reference in New Issue