ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
JobResult.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Cron\Job;
22 
23 class JobResult
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 
36  protected int $status = self::STATUS_NO_ACTION;
37  protected string $message = '';
38  protected ?string $code = null;
39  protected string $duration = '0';
40 
44  public static function getCoreCodes(): array
45  {
46  return [
47  self::CODE_NO_RESULT,
48  self::CODE_MANUAL_RESET,
49  self::CODE_SUPPOSED_CRASH,
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 [
79  self::STATUS_INVALID_CONFIGURATION,
80  self::STATUS_NO_ACTION,
81  self::STATUS_OK,
82  self::STATUS_CRASHED,
83  self::STATUS_FAIL,
84  self::STATUS_RESET,
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 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static strLen(string $a_string)
Definition: class.ilStr.php:63