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

daycry / jobs / 19498141349

19 Nov 2025 10:30AM UTC coverage: 62.5% (+0.7%) from 61.815%
19498141349

push

github

daycry
- Fixes

4 of 4 new or added lines in 4 files covered. (100.0%)

41 existing lines in 9 files now uncovered.

1145 of 1832 relevant lines covered (62.5%)

4.69 hits per line

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

93.62
/src/Queues/DatabaseQueue.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\Queues;
15

16
use DateTime;
17
use DateTimeZone;
18
use Daycry\Jobs\Entities\Queue as QueueEntity;
19
use Daycry\Jobs\Interfaces\QueueInterface;
20
use Daycry\Jobs\Interfaces\WorkerInterface;
21
use Daycry\Jobs\Job as QueuesJob;
22
use Daycry\Jobs\Libraries\DateTimeHelper;
23
use Daycry\Jobs\Models\QueueModel;
24

25
/**
26
 * Database-backed queue (persistent) implementing scheduling & status tracking.
27
 * watch(): devuelve QueueEntity o null.
28
 */
29
class DatabaseQueue extends BaseQueue implements QueueInterface, WorkerInterface
30
{
31
    private int $priority = 0;
32
    private mixed $job    = null;
33

34
    public function enqueue(object $data): string
35
    {
36
        helper('text');
6✔
37

38
        $identifier = random_string('alnum', 32);
6✔
39

40
        $queueModel = new QueueModel();
6✔
41
        $job        = new QueueEntity();
6✔
42

43
        $delay = $this->calculateDelay($data);
6✔
44

45
        if ($delay->isImmediate()) {
6✔
46
            $data->schedule = new DateTime('now', new DateTimeZone(config('App')->appTimezone));
6✔
47
        }
48

49
        $data->identifier = $identifier;
6✔
50

51
        $job->queue      = $data->queue;
6✔
52
        $job->payload    = \json_encode($data);
6✔
53
        $job->priority   = $data->priority;
6✔
54
        $job->schedule   = $data->schedule->format('Y-m-d H:i:s');
6✔
55
        $job->identifier = $identifier;
6✔
56
        $job->status     = 'pending';
6✔
57

58
        $queueModel->insert($job);
6✔
59

60
        return $identifier;
6✔
61
    }
62

63
    public function watch(string $queue): ?JobEnvelope
64
    {
65
        $queueModel = new QueueModel();
3✔
66

67
        $this->job = $queueModel->getJob();
3✔
68

69
        if ($this->job !== null) {
3✔
70
            $this->job->status     = 'in_progress';
3✔
71
            $this->job->updated_at = date('Y-m-d H:i:s');
3✔
72
            $queueModel->update($this->job->id, $this->job);
3✔
73

74
            $decoded = \json_decode($this->job->payload ?? '{}');
3✔
75

76
            return JobEnvelope::fromBackend(
3✔
77
                backend: 'database',
3✔
78
                id: (string) $this->job->identifier,
3✔
79
                queue: (string) $this->job->queue,
3✔
80
                payload: $decoded,
3✔
81
                extraMeta: [
3✔
82
                    'entity_id' => $this->job->id,
3✔
83
                    'status'    => $this->job->status,
3✔
84
                    'schedule'  => $this->job->schedule ?? null,
3✔
85
                ],
3✔
86
                raw: $this->job,
3✔
87
            );
3✔
88
        }
89

UNCOV
90
        return null;
×
91
    }
92

93
    public function removeJob(QueuesJob $job, bool $recreate = false): bool
94
    {
95
        $queueModel = new QueueModel();
2✔
96

97
        if ($recreate === true) {
2✔
98
            $this->job->status = 'failed';
1✔
99
            $queueModel->update($this->job->id, $this->job);
1✔
100
            // Re-enqueue directly to this database backend instead of using push()
101
            // which might use a different worker from QueueManager
102
            $this->enqueue($job->toObject());
1✔
103
        } else {
104
            $this->job->status = 'completed';
1✔
105
            $queueModel->update($this->job->id, $this->job);
1✔
106
        }
107

108
        $this->job = null;
2✔
109

110
        return true;
2✔
111
    }
112

113
    public function setPriority(int $priority)
114
    {
UNCOV
115
        $this->priority = $priority;
×
116

UNCOV
117
        return $this;
×
118
    }
119
}
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