ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBackgroundTaskGarbageCollection.php
Go to the documentation of this file.
1<?php
2
23
28{
33
34 public function __construct()
35 {
36 global $DIC;
37
38 $this->logger = $DIC->logger()->bgtk();
39 $this->lng = $DIC->language();
40 $this->lng->loadLanguageModule('background_tasks');
41 $this->persistence = $DIC->backgroundTasks()->persistence();
42
43 $this->result = new JobResult();
44 }
45
46 public function getTitle(): string
47 {
48 return $this->lng->txt('background_task_garbage_collection');
49 }
50
51 public function getDescription(): string
52 {
53 return $this->lng->txt('background_task_garbage_collection_info');
54 }
55
56 public function getId(): string
57 {
58 return 'background_task_garbage_collection';
59 }
60
61 public function hasAutoActivation(): bool
62 {
63 return false;
64 }
65
66 public function hasFlexibleSchedule(): bool
67 {
68 return true;
69 }
70
72 {
73 return JobScheduleType::IN_HOURS;
74 }
75
76 public function getDefaultScheduleValue(): ?int
77 {
78 return 1;
79 }
80
81 public function run(): JobResult
82 {
83 $this->logger->debug('Starting background task garbage collector..');
84
85 try {
86 $this->persistence->garbageCollection();
87 } catch (Exception $e) {
88 $this->result->setStatus(JobResult::STATUS_CRASHED);
89 $this->result->setMessage(mb_substr("Exc.: {$e->getMessage()} / {$e->getTraceAsString()}", 0, 400));
90 $this->logger->error("Background-Task Garbage Collection execution failed with message: {$e->getMessage()}");
91 $this->logger->error($e->getTraceAsString());
92 return $this->result;
93 }
94
95 $this->result->setStatus(JobResult::STATUS_OK);
96 return $this->result;
97 }
98}
setStatus(int $a_value)
Definition: JobResult.php:58
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
language handling
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26