ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilCronEcsTaskScheduler.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  public const ID = 'ecs_task_handler';
30  public const DEFAULT_SCHEDULE_VALUE = 1;
31 
32  private ilLogger $logger;
33  private ilLanguage $lng;
35 
36  public function __construct()
37  {
38  global $DIC;
39 
40  $this->logger = $DIC->logger()->wsrv();
41  $this->lng = $DIC->language();
42  $this->lng->loadLanguageModule('ecs');
43 
44  $this->result = new \ilCronJobResult();
45  }
46 
47  public function getTitle(): string
48  {
49  return $this->lng->txt('ecs_cron_task_scheduler');
50  }
51 
52  public function getDescription(): string
53  {
54  return $this->lng->txt('ecs_cron_task_scheduler_info');
55  }
56 
57  public function getId(): string
58  {
59  return self::ID;
60  }
61 
62  public function hasAutoActivation(): bool
63  {
64  return false;
65  }
66 
67  public function hasFlexibleSchedule(): bool
68  {
69  return true;
70  }
71 
73  {
74  return CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS;
75  }
76 
77  public function getDefaultScheduleValue(): ?int
78  {
79  return self::DEFAULT_SCHEDULE_VALUE;
80  }
81 
82  public function run(): ilCronJobResult
83  {
84  $this->logger->debug('Starting ecs task scheduler...');
85 
87 
88  foreach ($servers->getServers(ilECSServerSettings::ACTIVE_SERVER) as $server) {
89  try {
90  $this->logger->info('Starting task execution for ecs server: ' . $server->getTitle());
91  $scheduler = \ilECSTaskScheduler::_getInstanceByServerId($server->getServerId());
92  $scheduler->startTaskExecution();
93  } catch (Exception $e) {
94  $this->result->setStatus(\ilCronJobResult::STATUS_CRASHED);
95  $this->result->setMessage(
96  mb_substr(sprintf('Exc.: %s / %s', $e->getMessage(), $e->getTraceAsString()), 0, 400)
97  );
98  $this->logger->error('ECS task execution failed with message: ' . $e->getMessage());
99  $this->logger->error($e->getTraceAsString());
100  return $this->result;
101  }
102  }
103  $this->result->setStatus(\ilCronJobResult::STATUS_OK);
104  return $this->result;
105  }
106 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Get singleton instance.
Class ilCronEcsTaskScheduler.
global $DIC
Definition: shib_login.php:25
static _getInstanceByServerId($a_server_id)
get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTas...
$server
Definition: shib_login.php:27