|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ------------------------------------------------------------------------- |
| 5 | + * Carbon plugin for GLPI |
| 6 | + * |
| 7 | + * @copyright Copyright (C) 2024-2025 Teclib' and contributors. |
| 8 | + * @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+ |
| 9 | + * @link https://github.com/pluginsGLPI/carbon |
| 10 | + * |
| 11 | + * ------------------------------------------------------------------------- |
| 12 | + * |
| 13 | + * LICENSE |
| 14 | + * |
| 15 | + * This file is part of Carbon plugin for GLPI. |
| 16 | + * |
| 17 | + * This program is free software: you can redistribute it and/or modify |
| 18 | + * it under the terms of the GNU General Public License as published by |
| 19 | + * the Free Software Foundation, either version 3 of the License, or |
| 20 | + * (at your option) any later version. |
| 21 | + * |
| 22 | + * This program is distributed in the hope that it will be useful, |
| 23 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | + * GNU General Public License for more details. |
| 26 | + * |
| 27 | + * You should have received a copy of the GNU General Public License |
| 28 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 29 | + * |
| 30 | + * ------------------------------------------------------------------------- |
| 31 | + */ |
| 32 | + |
| 33 | +namespace GlpiPlugin\Carbon\DataSource\CarbonIntensity\Rte; |
| 34 | + |
| 35 | +use CronTask as GlpiCronTask; |
| 36 | +use GlpiPlugin\Carbon\CarbonIntensity; |
| 37 | +use GlpiPlugin\Carbon\CronTask as CarbonCronTask; |
| 38 | +use GlpiPlugin\Carbon\DataSource\CarbonIntensity\ClientFactory; |
| 39 | +use GlpiPlugin\Carbon\DataSource\CronTaskInterface; |
| 40 | + |
| 41 | +class CronTask implements CronTaskInterface |
| 42 | +{ |
| 43 | + public static function enumerateTasks(): array |
| 44 | + { |
| 45 | + // TODO: This data shoud replace the occurrence in CronTask::cronInfo() |
| 46 | + return [ |
| 47 | + [ |
| 48 | + 'itemtype' => self::class, |
| 49 | + 'name' => 'DownloadRte', |
| 50 | + 'frequency' => DAY_TIMESTAMP, |
| 51 | + 'options' => [ |
| 52 | + 'mode' => GlpiCronTask::MODE_EXTERNAL, |
| 53 | + 'allowmode' => GlpiCronTask::MODE_INTERNAL + GlpiCronTask::MODE_EXTERNAL, |
| 54 | + 'logs_lifetime' => 30, |
| 55 | + 'comment' => __('Compute carbon emissions of computers', 'carbon'), |
| 56 | + 'param' => 10000, // Maximum rows to generate per execution |
| 57 | + ] |
| 58 | + ] |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Get description of an automatic action |
| 64 | + * |
| 65 | + * @param string $name |
| 66 | + * @return array |
| 67 | + */ |
| 68 | + public static function cronInfo(string $name) |
| 69 | + { |
| 70 | + switch ($name) { |
| 71 | + case 'DownloadRte': |
| 72 | + return [ |
| 73 | + 'description' => __('Download carbon emissions from RTE', 'carbon'), |
| 74 | + 'parameter' => __('Maximum number of entries to download', 'carbon'), |
| 75 | + ]; |
| 76 | + } |
| 77 | + return []; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Automatic action for RTE datasource |
| 82 | + * |
| 83 | + * @return int |
| 84 | + */ |
| 85 | + public static function cronDownloadRte(GlpiCronTask $task): int |
| 86 | + { |
| 87 | + $client = ClientFactory::create('Rte'); |
| 88 | + return CarbonCronTask::downloadCarbonIntensityFromSource($task, $client, new CarbonIntensity()); |
| 89 | + } |
| 90 | +} |
0 commit comments