• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / jobs / 24850441053

23 Apr 2026 05:54PM UTC coverage: 52.404% (-1.5%) from 53.938%
24850441053

push

github

daycry
Fixes

104 of 219 new or added lines in 42 files covered. (47.49%)

14 existing lines in 9 files now uncovered.

1210 of 2309 relevant lines covered (52.4%)

4.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.39
/src/Commands/CronJobListCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Queues.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Jobs\Commands;
15

16
use Throwable;
17
use CodeIgniter\CLI\CLI;
18
use CodeIgniter\I18n\Time;
19
use Cron\CronExpression;
20

21
/**
22
 * Lists currently scheduled cron jobs including last and next run times (if logging supports history).
23
 */
24
class CronJobListCommand extends BaseJobsCommand
25
{
26
    /**
27
     * The Command's name
28
     *
29
     * @var string
30
     */
31
    protected $name = 'jobs:cronjob:list';
32

33
    /**
34
     * the Command's short description
35
     *
36
     * @var string
37
     */
38
    protected $description = 'Lists the cronjobs currently set to run.';
39

40
    /**
41
     * the Command's usage
42
     *
43
     * @var string
44
     */
45
    protected $usage = 'jobs:cronjob:list';
46

47
    /**
48
     * Lists upcoming tasks
49
     */
50
    public function run(array $params): int
51
    {
52
        $this->getConfig();
1✔
53
        if (! $this->isActive()) {
1✔
54
            $this->tryToEnable();
×
55

NEW
56
            return self::FAILURE;
×
57
        }
58

59
        $scheduler = service('scheduler');
1✔
60
        config('Jobs')->init($scheduler);
1✔
61

62
        $jobs = [];
1✔
63

64
        // Instanciar una sola vez el handler de logging si la configuración es válida
65
        $handler = null;
1✔
66
        if (isset($this->config->loggers[$this->config->log])) {
1✔
67
            $class = $this->config->loggers[$this->config->log];
1✔
68
            if (class_exists($class)) {
1✔
69
                try {
70
                    $handler = new $class();
1✔
NEW
71
                } catch (Throwable) {
×
72
                    $handler = null; // Falla silenciosa: seguimos sin last_run
×
73
                }
74
            }
75
        }
76

77
        foreach ($scheduler->getJobs() as $job) {
1✔
78
            $cron    = new CronExpression($job->getExpression());
1✔
79
            $nextRun = ($job->isEnabled()) ? $cron->getNextRunDate()->format('Y-m-d H:i:s') : '--';
1✔
80

81
            $lastRunValue = '--';
1✔
82
            if ($handler && method_exists($handler, 'lastRun')) {
1✔
83
                try {
84
                    $lr           = $handler->lastRun($job->getName());
1✔
85
                    $lastRunValue = $lr instanceof Time ? $lr->format('Y-m-d H:i:s') : ($lr ?: '--');
1✔
NEW
86
                } catch (Throwable) {
×
87
                    // Ignorar errores al obtener el último run
88
                }
89
            }
90

91
            $jobs[] = [
1✔
92
                'name'     => $job->getName() ?: $job->getJob(),
1✔
93
                'job'      => $job->getJob(),
1✔
94
                'schedule' => $job->getExpression(),
1✔
95
                'last_run' => $lastRunValue,
1✔
96
                'next_run' => $nextRun,
1✔
97
            ];
1✔
98
        }
99

100
        // Ordenar por próxima ejecución; los deshabilitados ('--') siempre al final
101
        usort($jobs, static function ($a, $b) {
1✔
102
            $na = $a['next_run'];
1✔
103
            $nb = $b['next_run'];
1✔
104
            if ($na === $nb) {
1✔
105
                return 0;
1✔
106
            }
107
            if ($na === '--') {
×
108
                return 1; // a va después
×
109
            }
110
            if ($nb === '--') {
×
111
                return -1; // b va después
×
112
            }
113

114
            return $na <=> $nb;
×
115
        });
1✔
116

117
        CLI::table(
1✔
118
            $jobs,
1✔
119
            [
1✔
120
                'Name',
1✔
121
                'Type',
1✔
122
                'Expression',
1✔
123
                'Last Run',
1✔
124
                'Next Run',
1✔
125
            ],
1✔
126
        );
1✔
127

128
        return self::SUCCESS;
1✔
129
    }
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc