2017-08-16 14:01:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Widget;
|
|
|
|
|
2020-10-26 18:50:13 +01:00
|
|
|
use gipfl\Web\Widget\Hint;
|
2019-09-17 15:06:39 +02:00
|
|
|
use Icinga\Date\DateFormatter;
|
2019-05-02 13:23:06 +02:00
|
|
|
use ipl\Html\HtmlDocument;
|
2017-08-16 14:01:43 +02:00
|
|
|
use Icinga\Module\Director\Objects\DirectorJob;
|
2019-05-02 13:23:06 +02:00
|
|
|
use ipl\Html\Html;
|
|
|
|
use gipfl\Translation\TranslationHelper;
|
2017-08-16 14:01:43 +02:00
|
|
|
|
2018-05-08 19:54:00 +02:00
|
|
|
class JobDetails extends HtmlDocument
|
2017-08-16 14:01:43 +02:00
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
2018-05-08 19:54:00 +02:00
|
|
|
/**
|
|
|
|
* JobDetails constructor.
|
|
|
|
* @param DirectorJob $job
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2017-08-16 14:01:43 +02:00
|
|
|
public function __construct(DirectorJob $job)
|
|
|
|
{
|
2019-09-17 15:06:39 +02:00
|
|
|
$runInterval = $job->get('run_interval');
|
|
|
|
if ($job->hasBeenDisabled()) {
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->add(Hint::error(sprintf(
|
2017-08-16 14:01:43 +02:00
|
|
|
$this->translate(
|
|
|
|
'This job would run every %ds. It has been disabled and will'
|
|
|
|
. ' therefore not be executed as scheduled'
|
|
|
|
),
|
2019-09-17 15:06:39 +02:00
|
|
|
$runInterval
|
2017-08-16 14:01:43 +02:00
|
|
|
)));
|
|
|
|
} else {
|
|
|
|
//$class = $job->job(); echo $class::getDescription()
|
|
|
|
$msg = $job->isPending()
|
|
|
|
? sprintf(
|
|
|
|
$this->translate('This job runs every %ds and is currently pending'),
|
2019-09-17 15:06:39 +02:00
|
|
|
$runInterval
|
2017-08-16 14:01:43 +02:00
|
|
|
)
|
|
|
|
: sprintf(
|
|
|
|
$this->translate('This job runs every %ds.'),
|
2019-09-17 15:06:39 +02:00
|
|
|
$runInterval
|
2017-08-16 14:01:43 +02:00
|
|
|
);
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', null, $msg));
|
2017-08-16 14:01:43 +02:00
|
|
|
}
|
|
|
|
|
2019-09-17 15:06:39 +02:00
|
|
|
$tsLastAttempt = $job->get('ts_last_attempt');
|
|
|
|
$ts = \strtotime($tsLastAttempt);
|
|
|
|
$timeAgo = Html::tag('span', [
|
|
|
|
'class' => 'time-ago',
|
|
|
|
'title' => DateFormatter::formatDateTime($ts)
|
|
|
|
], DateFormatter::timeAgo($ts));
|
|
|
|
if ($tsLastAttempt) {
|
|
|
|
if ($job->get('last_attempt_succeeded') === 'y') {
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->add(Hint::ok(Html::sprintf(
|
2019-09-17 15:06:39 +02:00
|
|
|
$this->translate('The last attempt succeeded %s'),
|
|
|
|
$timeAgo
|
2017-08-16 14:01:43 +02:00
|
|
|
)));
|
|
|
|
} else {
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->add(Hint::error(Html::sprintf(
|
2019-09-17 15:06:39 +02:00
|
|
|
$this->translate('The last attempt failed %s: %s'),
|
|
|
|
$timeAgo,
|
|
|
|
$job->get('last_error_message')
|
2017-08-16 14:01:43 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->add(Hint::warning($this->translate('This job has not been executed yet')));
|
2017-08-16 14:01:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|