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

daycry / jobs / 24458365411

05 Apr 2026 08:48AM UTC coverage: 53.938% (-2.2%) from 56.164%
24458365411

push

github

daycry
Optimize

50 of 192 new or added lines in 14 files covered. (26.04%)

3 existing lines in 3 files now uncovered.

1219 of 2260 relevant lines covered (53.94%)

4.42 hits per line

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

0.0
/src/Libraries/DeadLetterQueue.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\Libraries;
15

16
use Daycry\Jobs\Job;
17
use Throwable;
18

19
/**
20
 * Dead Letter Queue manager.
21
 * Handles jobs that have permanently failed after exhausting all retries.
22
 */
23
class DeadLetterQueue
24
{
25
    /**
26
     * Move a job to the dead letter queue.
27
     *
28
     * @param Job    $job      Failed job
29
     * @param string $reason   Failure reason
30
     * @param int    $attempts Number of attempts made
31
     */
32
    public function store(Job $job, string $reason, int $attempts): void
33
    {
34
        $config  = ConfigCache::get();
×
35
        $dlqName = $config->deadLetterQueue;
×
36

37
        if (! $dlqName) {
×
38
            return; // DLQ disabled
×
39
        }
40

41
        // Add metadata about the failure
42
        $metadata = [
×
43
            'dlq_reason'     => $reason,
×
44
            'dlq_timestamp'  => date('Y-m-d H:i:s'),
×
45
            'dlq_attempts'   => $attempts,
×
46
            'original_queue' => $job->getQueue(),
×
47
        ];
×
48

49
        // Create a new job instance for DLQ
50
        $dlqJob = clone $job;
×
NEW
51
        $dlqJob->setQueue($dlqName);
×
52

53
        // Store metadata in payload if possible
54
        $payload = $dlqJob->getPayload();
×
55
        if (is_array($payload)) {
×
56
            $payload['_dlq_metadata'] = $metadata;
×
57
            $dlqJob->setPayload($payload);
×
58
        }
59

60
        // Push to DLQ
61
        try {
62
            $dlqJob->push();
×
63
            log_message('info', "Job {$job->getName()} moved to DLQ after {$attempts} attempts. Reason: {$reason}");
×
64
        } catch (Throwable $e) {
×
65
            log_message('error', "Failed to store job in DLQ: {$e->getMessage()}");
×
66
        }
67
    }
68

69
    /**
70
     * Get statistics about dead letter queue.
71
     */
72
    public function getStats(): array
73
    {
74
        $config  = ConfigCache::get();
×
75
        $dlqName = $config->deadLetterQueue;
×
76

77
        if (! $dlqName) {
×
78
            return ['enabled' => false];
×
79
        }
80

81
        // This would require queue backend support to count jobs
82
        return [
×
83
            'enabled' => true,
×
84
            'queue'   => $dlqName,
×
85
        ];
×
86
    }
87
}
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