1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TreeHouse\WorkerBundle\Exception; |
4
|
|
|
|
5
|
|
|
class RescheduleException extends \Exception |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var \DateTime |
9
|
|
|
*/ |
10
|
|
|
private $rescheduleDate; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $rescheduleMessage; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var integer |
19
|
|
|
*/ |
20
|
|
|
private $reshedulePriority; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \DateTime $date |
24
|
|
|
*/ |
25
|
2 |
|
public function setRescheduleDate(\DateTime $date) |
26
|
|
|
{ |
27
|
2 |
|
$this->rescheduleDate = $date; |
28
|
2 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return \DateTime |
32
|
|
|
*/ |
33
|
2 |
|
public function getRescheduleDate() |
34
|
|
|
{ |
35
|
2 |
|
return $this->rescheduleDate; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $msg |
40
|
|
|
*/ |
41
|
2 |
|
public function setRescheduleMessage($msg = null) |
42
|
|
|
{ |
43
|
2 |
|
$this->rescheduleMessage = $msg; |
44
|
2 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getRescheduleMessage() |
50
|
|
|
{ |
51
|
|
|
return $this->rescheduleMessage; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Factory method. |
56
|
|
|
* |
57
|
|
|
* @param string $time Time difference after which the job should be rescheduled. |
58
|
|
|
* Can be anything that strtotime accepts, without the `+` sign, eg: '10 seconds' |
59
|
|
|
* @param string $msg |
60
|
|
|
* |
61
|
|
|
* @param integer $newPriority A new priority to apply the the job. If omitted the current priority will be used. |
62
|
|
|
* |
63
|
|
|
* @return RescheduleException |
64
|
|
|
*/ |
65
|
2 |
|
public static function create($time, $msg = null, $newPriority = null) |
66
|
|
|
{ |
67
|
2 |
|
$re = new RescheduleException($msg); |
68
|
2 |
|
$re->setRescheduleDate(new \DateTime('@' . strtotime('+' . $time))); |
69
|
2 |
|
$re->setRescheduleMessage($msg); |
70
|
2 |
|
$re->setReshedulePriority($newPriority); |
71
|
|
|
|
72
|
2 |
|
return $re; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return integer |
77
|
|
|
*/ |
78
|
2 |
|
public function getReshedulePriority() |
79
|
|
|
{ |
80
|
2 |
|
return $this->reshedulePriority; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param integer $reshedulePriority |
85
|
|
|
*/ |
86
|
2 |
|
public function setReshedulePriority($reshedulePriority) |
87
|
|
|
{ |
88
|
2 |
|
$this->reshedulePriority = $reshedulePriority; |
89
|
2 |
|
} |
90
|
|
|
} |
91
|
|
|
|