summaryrefslogtreecommitdiff
path: root/vendor/fguillot/simple-queue/src/Queue.php
blob: a88b55cb0ff46aa85ee1f7255b0a8d2dbdf0a81d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

namespace SimpleQueue;

use DateTime;

/**
 * Class Queue
 *
 * @package SimpleQueue
 */
class Queue implements QueueAdapterInterface
{
    /**
     * @var QueueAdapterInterface
     */
    protected $queueAdapter;

    /**
     * Queue constructor.
     *
     * @param QueueAdapterInterface $queueAdapter
     */
    public function __construct(QueueAdapterInterface $queueAdapter)
    {
        $this->queueAdapter = $queueAdapter;
    }

    /**
     * Send a job
     *
     * @access public
     * @param  Job $job
     * @return $this
     */
    public function push(Job $job)
    {
        $this->queueAdapter->push($job);
        return $this;
    }

    /**
     * Schedule a job in the future
     *
     * @access public
     * @param  Job      $job
     * @param  DateTime $dateTime
     * @return $this
     */
    public function schedule(Job $job, DateTime $dateTime)
    {
        $this->queueAdapter->schedule($job, $dateTime);
        return $this;
    }

    /**
     * Wait and get job from a queue
     *
     * @access public
     * @return Job|null
     */
    public function pull()
    {
        return $this->queueAdapter->pull();
    }

    /**
     * Acknowledge a job
     *
     * @access public
     * @param  Job $job
     * @return $this
     */
    public function completed(Job $job)
    {
        $this->queueAdapter->completed($job);
        return $this;
    }

    /**
     * Mark a job as failed
     *
     * @access public
     * @param  Job $job
     * @return $this
     */
    public function failed(Job $job)
    {
        $this->queueAdapter->failed($job);
        return $this;
    }
}