-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIsStopableConsumer.php
More file actions
54 lines (44 loc) · 1.08 KB
/
IsStopableConsumer.php
File metadata and controls
54 lines (44 loc) · 1.08 KB
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
<?php
namespace Smartbox\Integration\FrameworkBundle\Core\Consumers;
trait IsStopableConsumer {
/** @var bool */
protected $stop = false;
/** @var int */
protected $expirationCount = -1;
/** @var int */
protected $expirationTime = 100 * 365 * 24 * 60 * 60;
/**
* {@inheritDoc}
*/
public function stop()
{
$this->stop = true;
}
/**
* {@inheritDoc}
*/
public function setExpirationCount($count)
{
$this->expirationCount = $count;
}
/**
* {@inheritDoc}
*/
public function setExpirationTime($time)
{
$this->expirationTime = 100 * 365 * 24 * 60 * 60; // 100 years after Unix Epoch
if ($time > 0) {
$this->expirationTime = time() + $time; // $time seconds after now
}
}
/**
* Checks if it should stop at the current iteration.
*
* @return bool
*/
protected function shouldStop()
{
pcntl_signal_dispatch();
return $this->stop || $this->expirationCount == 0 || time() > $this->expirationTime;
}
}