CC: | sebastien.bocahu [...] nuxit.com |
Subject: | Option to sleep and retry on error |
Add option to sleep and retry in the worker loop instead of dying.
Subject: | GearmanXStarter.patch |
--- Starter.pm.orig 2012-10-15 15:50:48.000000000 +0200
+++ Starter.pm 2012-10-15 16:05:03.000000000 +0200
@@ -35,6 +35,8 @@
my $sigterm = $args->{sigterm} || [ 'TERM' ];
+ my $sleep = $args->{sleep_and_retry};
+
$logger->info("Forking daemon for $worker_name") if $logger;
_Init() and return 1;
@@ -92,8 +94,14 @@
1;
};
if ( !$res && $@ !~ /GearmanXQuitLoop/ ) {
- $logger->logdie("Error running loop for worker $worker_name [$@]:". $WORKER->error)
- if $logger;
+ if ($sleep) {
+ $logger->logwarn("Error running loop for worker $worker_name [$@]:".$WORKER->error.
+ " -- Going to sleep for ${sleep}s") if $logger;
+ sleep $sleep;
+ } else {
+ $logger->logdie("Error running loop for worker $worker_name [$@]:".$WORKER->error)
+ if $logger;
+ }
}
last if $QUIT;
}