ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
JobResult.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Cron\Job;
22
24{
25 final public const int STATUS_INVALID_CONFIGURATION = 1;
26 final public const int STATUS_NO_ACTION = 2;
27 final public const int STATUS_OK = 3;
28 final public const int STATUS_CRASHED = 4;
29 final public const int STATUS_RESET = 5;
30 final public const int STATUS_FAIL = 6;
31
32 final public const string CODE_NO_RESULT = 'job_no_result';
33 final public const string CODE_MANUAL_RESET = 'job_manual_reset';
34 final public const string CODE_SUPPOSED_CRASH = 'job_auto_deactivation_time_limit';
35
37 protected string $message = '';
38 protected ?string $code = null;
39 protected string $duration = '0';
40
44 public static function getCoreCodes(): array
45 {
46 return [
50 ];
51 }
52
53 public function getStatus(): int
54 {
55 return $this->status;
56 }
57
58 public function setStatus(int $a_value): void
59 {
60 if (!\in_array($a_value, $this->getValidStatus(), true)) {
61 throw new \InvalidArgumentException(
62 \sprintf(
63 'The passed status "%s" is not valid, must be of one of: %s',
64 $a_value,
65 implode(', ', $this->getValidStatus())
66 )
67 );
68 }
69
70 $this->status = $a_value;
71 }
72
76 protected function getValidStatus(): array
77 {
78 return [
85 ];
86 }
87
88 public function getMessage(): string
89 {
90 return $this->message;
91 }
92
93 public function setMessage(string $value): void
94 {
95 $value = trim($value);
96 if (\ilStr::strLen($value) > 400) {
97 throw new \InvalidArgumentException('The message must not exceed 400 characters');
98 }
99
100 $this->message = $value;
101 }
102
103 public function getCode(): ?string
104 {
105 return $this->code;
106 }
107
108 public function setCode(string $a_value): void
109 {
110 if (!\in_array($a_value, self::getCoreCodes(), true)) {
111 throw new \InvalidArgumentException(
112 \sprintf(
113 'The passed code "%s" is not valid, must be of one of: %s',
114 $a_value,
115 implode(', ', self::getCoreCodes())
116 )
117 );
118 }
119
120 $this->code = $a_value;
121 }
122
123 public function getDuration(): float
124 {
125 return (float) $this->duration;
126 }
127
128 public function setDuration(float $a_value): void
129 {
130 $this->duration = number_format($a_value, 3, '.', '');
131 }
132}
setMessage(string $value)
Definition: JobResult.php:93
final const int STATUS_FAIL
Definition: JobResult.php:30
final const int STATUS_RESET
Definition: JobResult.php:29
setDuration(float $a_value)
Definition: JobResult.php:128
final const int STATUS_CRASHED
Definition: JobResult.php:28
setCode(string $a_value)
Definition: JobResult.php:108
final const string CODE_SUPPOSED_CRASH
Definition: JobResult.php:34
final const string CODE_NO_RESULT
Definition: JobResult.php:32
final const int STATUS_NO_ACTION
Definition: JobResult.php:26
final const string CODE_MANUAL_RESET
Definition: JobResult.php:33
final const int STATUS_OK
Definition: JobResult.php:27
setStatus(int $a_value)
Definition: JobResult.php:58
final const int STATUS_INVALID_CONFIGURATION
Definition: JobResult.php:25
static strLen(string $a_string)
Definition: class.ilStr.php:60