|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of ILIAS, a powerful learning management system |
| 7 | + * published by ILIAS open source e-Learning e.V. |
| 8 | + * |
| 9 | + * ILIAS is licensed with the GPL-3.0, |
| 10 | + * see https://www.gnu.org/licenses/gpl-3.0.en.html |
| 11 | + * You should have received a copy of said license along with the |
| 12 | + * source code, too. |
| 13 | + * |
| 14 | + * If this is not the case or you just want to try ILIAS, you'll find |
| 15 | + * us at: |
| 16 | + * https://www.ilias.de |
| 17 | + * https://github.com/ILIAS-eLearning |
| 18 | + * |
| 19 | + ******************************************************************** |
| 20 | + */ |
| 21 | + |
| 22 | +use ILIAS\Setup; |
| 23 | + |
| 24 | +class ilCronJobsMetricsCollectedObjective extends Setup\Metrics\CollectedObjective |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @inheritDoc |
| 28 | + */ |
| 29 | + protected function getTentativePreconditions(Setup\Environment $environment): array |
| 30 | + { |
| 31 | + return [ |
| 32 | + new ilIniFilesLoadedObjective(), |
| 33 | + new ilDatabaseInitializedObjective(), |
| 34 | + new ilComponentRepositoryExistsObjective(), |
| 35 | + new ilComponentFactoryExistsObjective() |
| 36 | + ]; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @inheritDoc |
| 41 | + */ |
| 42 | + protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void |
| 43 | + { |
| 44 | + $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE); |
| 45 | + $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY); |
| 46 | + $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY); |
| 47 | + $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY); |
| 48 | + |
| 49 | + $mock_lng = new class () implements \ILIAS\Language\Language { |
| 50 | + public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string |
| 51 | + { |
| 52 | + return ''; |
| 53 | + } |
| 54 | + public function loadLanguageModule(string $a_module): void |
| 55 | + { |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + $repo = new ilCronJobRepositoryImpl( |
| 60 | + $db, |
| 61 | + $settings_factory->settingsFor(), |
| 62 | + new ILIAS\components\Logging\NullLogger(), |
| 63 | + $component_repository, |
| 64 | + $component_factory, |
| 65 | + $mock_lng |
| 66 | + ); |
| 67 | + |
| 68 | + //@var ilCronJobEntity[] |
| 69 | + $collection = $repo->findAll()->toArray(); |
| 70 | + $cron_jobs = []; |
| 71 | + foreach ($collection as $entity) { |
| 72 | + $active = new Setup\Metrics\Metric( |
| 73 | + Setup\Metrics\Metric::STABILITY_VOLATILE, |
| 74 | + Setup\Metrics\Metric::TYPE_BOOL, |
| 75 | + (bool) $entity->getJobStatus(), |
| 76 | + "Is the job active?" |
| 77 | + ); |
| 78 | + $component = new Setup\Metrics\Metric( |
| 79 | + Setup\Metrics\Metric::STABILITY_STABLE, |
| 80 | + Setup\Metrics\Metric::TYPE_TEXT, |
| 81 | + $entity->getComponent() |
| 82 | + ); |
| 83 | + $cron_jobs[$entity->getJobId()] = new Setup\Metrics\Metric( |
| 84 | + Setup\Metrics\Metric::STABILITY_MIXED, |
| 85 | + Setup\Metrics\Metric::TYPE_COLLECTION, |
| 86 | + [ |
| 87 | + "component" => $component, |
| 88 | + "active" => $active |
| 89 | + ] |
| 90 | + ); |
| 91 | + } |
| 92 | + $cron_jobs = new Setup\Metrics\Metric( |
| 93 | + Setup\Metrics\Metric::STABILITY_MIXED, |
| 94 | + Setup\Metrics\Metric::TYPE_COLLECTION, |
| 95 | + $cron_jobs |
| 96 | + ); |
| 97 | + |
| 98 | + $cron_jobs_count = new Setup\Metrics\Metric( |
| 99 | + Setup\Metrics\Metric::STABILITY_STABLE, |
| 100 | + Setup\Metrics\Metric::TYPE_GAUGE, |
| 101 | + count($collection) |
| 102 | + ); |
| 103 | + $storage->store( |
| 104 | + "number of cron jobs", |
| 105 | + $cron_jobs_count |
| 106 | + ); |
| 107 | + $storage->store( |
| 108 | + "cron jobs", |
| 109 | + $cron_jobs |
| 110 | + ); |
| 111 | + } |
| 112 | +} |
0 commit comments