Completed
Push — master ( 2ec33a...e1edf3 )
by Akihito
02:29
created

TaskQueue::queuedCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Ackintosh\Snidel;
3
4
use Ackintosh\Snidel\AbstractQueue;
5
use Ackintosh\Snidel\Task;
6
7
class TaskQueue extends AbstractQueue
8
{
9
    /**
10
     * @param   \Ackintosh\Snidel\Task  $task
11
     * @return  void
12
     * @throws  RuntimeException
13
     */
14
    public function enqueue($task)
15
    {
16
        $this->queuedCount++;
17
18
        if (!$this->sendMessage(Task::serialize($task))) {
19
            throw new \RuntimeException('failed to enqueue task.');
20
        }
21
    }
22
23
    /**
24
     * @return  \Ackintosh\Snidel\Task
25
     * @throws  \RuntimeException
26
     */
27
    public function dequeue()
28
    {
29
        $this->dequeuedCount++;
30
        try {
31
            $serializedTask = $this->receiveMessage();
32
        } catch (\RuntimeException $e) {
33
            throw new \RuntimeException('failed to dequeue task');
34
        }
35
36
        return Task::unserialize($serializedTask);
37
    }
38
}
39