• 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

20.0
/src/Traits/ActivityTrait.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\Traits;
15

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

20
/**
21
 * Adds retry/timeout metadata and schedule evaluation helpers to a Job.
22
 * Provides shouldRun() using cron expression & environment filtering, plus max retries and timeout accessors.
23
 */
24
trait ActivityTrait
25
{
26
    protected ?int $maxRetries = null;
27
    protected ?int $timeout    = null;
28

29
    public function maxRetries(int $retries): self
30
    {
31
        $this->maxRetries = $retries;
59✔
32

33
        return $this;
59✔
34
    }
35

36
    public function timeout(int $timeout): self
37
    {
38
        $this->timeout = $timeout;
58✔
39

40
        return $this;
58✔
41
    }
42

43
    public function getMaxRetries(): ?int
44
    {
45
        return $this->maxRetries ?? null;
31✔
46
    }
47

48
    /**
49
     * Get the timeout (in seconds) for this job.
50
     */
51
    public function getTimeout(): ?int
52
    {
53
        return $this->timeout ?? null;
29✔
54
    }
55

56
    public function shouldRun(?Time $testTime = null): bool
57
    {
58
        // Are we restricting to environments?
59
        if (! empty($this->environments) && ! $this->inEnvironment($_SERVER['CI_ENVIRONMENT'] ?? 'production')) {
×
60
            return false;
×
61
        }
62

63
        $cron = new CronExpression($this->getExpression());
×
64

65
        $testTime = ($testTime) ?: 'now';
×
66

67
        return $cron->isDue($testTime, config('App')->appTimezone);
×
68
    }
69

70
    /**
71
     * Returns the date this was last ran, using the configured logger handler.
72
     */
73
    public function lastRun(): string|Time
74
    {
75
        $config = config('Jobs');
×
76

77
        if ($config->logPerformance === false) {
×
78
            return '--';
×
79
        }
80

81
        $name = ($this->name ?? '') ?: $this->getName();
×
82

83
        $handler = $this->resolveLoggerHandler($config);
×
84
        if ($handler === null) {
×
85
            return '--';
×
86
        }
87

88
        return $handler->lastRun($name);
×
89
    }
90

91
    /**
92
     * Returns the last run time as a Time instance or null when not available.
93
     */
94
    public function getLastRunTime(): ?Time
95
    {
96
        $val = $this->lastRun();
×
97

98
        return $val instanceof Time ? $val : null;
×
99
    }
100

101
    /**
102
     * Resolve the configured logger handler instance (file or database).
103
     */
104
    private function resolveLoggerHandler(object $config): ?object
105
    {
106
        if (empty($config->log) || ! isset($config->loggers[$config->log])) {
×
107
            return null;
×
108
        }
109

110
        $class = $config->loggers[$config->log];
×
111

112
        if (! class_exists($class)) {
×
113
            return null;
×
114
        }
115

116
        try {
117
            $handler = new $class();
×
NEW
118
        } catch (Throwable) {
×
119
            return null;
×
120
        }
121

122
        return method_exists($handler, 'lastRun') ? $handler : null;
×
123
    }
124
}
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