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

daycry / jobs / 21145580946

19 Jan 2026 04:55PM UTC coverage: 58.025% (-4.5%) from 62.567%
21145580946

push

github

daycry
Add security, performance, and health features; simplify architecture

Introduces shell command whitelisting, smart token detection, per-queue rate limiting, dead letter queue, job timeout protection, config caching, and a health monitoring command. Refactors architecture by consolidating traits, removing the CompletionStrategy pattern, and unifying retry policies under RetryPolicyFixed. Updates documentation and tests to reflect new features and architectural changes, ensuring backward compatibility and improved reliability.

143 of 340 new or added lines in 20 files covered. (42.06%)

1 existing line in 1 file now uncovered.

1193 of 2056 relevant lines covered (58.03%)

4.44 hits per line

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

7.89
/src/Traits/StateTrait.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 Daycry\Jobs\Execution\ExecutionResult;
17
use Daycry\Jobs\Job;
18

19
/**
20
 * Unified trait for job state management and notifications.
21
 * Combines StatusTrait and NotificableTrait functionality.
22
 *
23
 * @mixin Job
24
 */
25
trait StateTrait
26
{
27
    protected bool $enabled         = true;
28
    protected bool $notifyOnFailure = false;
29
    protected bool $notifyOnSuccess = false;
30

31
    // ============================================================
32
    // Status & Single Instance (formerly StatusTrait)
33
    // ============================================================
34

35
    public function saveRunningFlag(): bool
36
    {
NEW
37
        $cache = service('cache');
×
38

NEW
39
        return $cache->save('job_running', $this->getName(), 0);
×
40
    }
41

42
    public function isRunning(): bool
43
    {
NEW
44
        $cache = service('cache');
×
45

NEW
46
        return (bool) ($cache->get('job_running') === $this->getName());
×
47
    }
48

49
    public function clearRunningFlag(): bool
50
    {
NEW
51
        $cache = service('cache');
×
52

NEW
53
        return $cache->delete('job_running');
×
54
    }
55

56
    public function disable(): self
57
    {
NEW
58
        $this->enabled = false;
×
59

NEW
60
        return $this;
×
61
    }
62

63
    public function isEnabled(): bool
64
    {
65
        return $this->enabled;
1✔
66
    }
67

68
    // ============================================================
69
    // Notifications (formerly NotificableTrait)
70
    // ============================================================
71

72
    public function notifyOnFailure(bool $notify = true): self
73
    {
74
        $this->notifyOnFailure = $notify;
×
75

76
        return $this;
×
77
    }
78

79
    public function notifyOnSuccess(bool $notify = true): self
80
    {
81
        $this->notifyOnSuccess = $notify;
×
82

83
        return $this;
×
84
    }
85

86
    public function shouldNotifyOnFailure(): bool
87
    {
88
        return $this->notifyOnFailure;
9✔
89
    }
90

91
    public function shouldNotifyOnSuccess(): bool
92
    {
93
        return $this->notifyOnSuccess;
11✔
94
    }
95

96
    public function notifyOnCompletion(bool $notify = true): self
97
    {
98
        $this->notifyOnFailure = $notify;
×
99
        $this->notifyOnSuccess = $notify;
×
100

101
        return $this;
×
102
    }
103

104
    public function notify(ExecutionResult $result): bool
105
    {
106
        $email  = service('email');
×
107
        $parser = service('parser');
×
108

109
        $content          = $result->success ? $result->output : $result->error;
×
110
        $normalizedOutput = null;
×
111
        if (is_array($content) || is_object($content)) {
×
112
            $normalizedOutput = json_encode($content);
×
113
        } elseif ($content !== null) {
×
114
            $normalizedOutput = (string) $content;
×
115
        }
116

117
        $email->setMailType('html');
×
118
        $email->setFrom(config('Jobs')->from, config('Jobs')->fromName);
×
119
        $email->setTo(config('Jobs')->to);
×
120
        $email->setSubject($parser->setData(['job' => $this->getName()])->renderString('Job {job} just finished running.'));
×
121
        $email->setMessage($parser->setData([
×
122
            'name'     => $this->getName(),
×
123
            'runStart' => null,
×
124
            'duration' => null,
×
125
            'output'   => ($result->success ? $normalizedOutput : null),
×
126
            'error'    => ($result->success !== true) ? $normalizedOutput : null,
×
127
        ])->render(config('Jobs')->emailNotificationView));
×
128

129
        return $email->send();
×
130
    }
131
}
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