From aeda915563f84e9c671ffda42fc8988697f95972 Mon Sep 17 00:00:00 2001 From: Emir Bugra Koksalan Date: Fri, 7 Jan 2022 23:50:12 +0300 Subject: [PATCH] minor changes --- worker.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worker.php b/worker.php index 89e837d..18a5ccd 100644 --- a/worker.php +++ b/worker.php @@ -15,7 +15,7 @@ while (true) { $job = null; try { - $job = $pheanstalk->reserveWithTimeout(3); + $job = $pheanstalk->reserveWithTimeout(10); if (is_null($job)) throw new Exception("Job is null"); @@ -26,7 +26,7 @@ while (true) { echo date('Y-m-d H:i:s') . ' ' . str_pad($jobPayload->id, 5, " ", STR_PAD_LEFT) . ' ' . $jobPayload->date . PHP_EOL; //echo date('Y-m-d H:i:s') . ' ' . str_pad($jobPayload->id, 5, " ", STR_PAD_LEFT) . ' ' . json_encode($jobPayload) . PHP_EOL; - usleep(mt_rand(1, 10)); + usleep(mt_rand(1, 100)); //sleep(2); // If it's going to take a long time, periodically // tell beanstalk we're alive to stop it rescheduling the job. @@ -41,10 +41,13 @@ while (true) { $pheanstalk->release($job); if (str_contains($e->getMessage(), 'Connection refused')) { - echo 'Beanstalkd server is down'; + echo 'Beanstalkd server is down' . PHP_EOL; die(); } else if (!($e instanceof Exception)) { echo $e->getMessage() . PHP_EOL; + } else { + echo "Timeout reached." . PHP_EOL; + die(); } } }