Skip to content

Commit 804bcf7

Browse files
committed
Update worker timeout
1 parent f9caf10 commit 804bcf7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/Queue/Adapters/QueueAdapter.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ abstract class QueueAdapter
2626
*/
2727
protected float $processing_timeout;
2828

29+
/**
30+
* Define the work time out
31+
*
32+
* @var integer
33+
*/
34+
protected int $timeout = 120;
35+
2936
/**
3037
* Determine the default watch name
3138
*
@@ -100,15 +107,26 @@ public function sleep(int $seconds): void
100107
}
101108
}
102109

110+
/**
111+
* Set worker timeout
112+
*
113+
* @param integer $timeout
114+
* @return void
115+
*/
116+
public function setTimeout(int $timeout): void
117+
{
118+
$this->timeout = $timeout;
119+
}
120+
103121
/**
104122
* Update the processing timeout
105123
*
106-
* @param int $timeout
124+
* @param int $timeout
107125
* @return void
108126
*/
109-
public function updateProcessingTimeout(int $timeout = 60): void
127+
public function updateProcessingTimeout(?int $timeout = null): void
110128
{
111-
$this->processing_timeout = time() + $timeout;
129+
$this->processing_timeout = time() + ($timeout ?? $this->timeout);
112130
}
113131

114132
/**
@@ -128,7 +146,8 @@ final public function work(int $timeout, int $memory): void
128146

129147
while (true) {
130148
try {
131-
$this->updateProcessingTimeout($timeout);
149+
$this->setTimeout($timeout);
150+
$this->updateProcessingTimeout();
132151
$this->run($this->queue);
133152
} finally {
134153
$this->sleep($this->sleep);

src/Queue/WorkerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function run(
4040
string $queue = "default",
4141
int $tries = 3,
4242
int $sleep = 5,
43-
int $timeout = 60,
43+
int $timeout = 120,
4444
int $memory = 128
4545
): void {
4646
$this->connection->setQueue($queue);

0 commit comments

Comments
 (0)