diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 0a633b45e9..416fbbac91 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -330,6 +330,11 @@ def select_jobs(self, where, args): cr.execute(query, args) return list(cr.fetchall()) + def keep_alive(self): + query = "SELECT 1" + with closing(self.conn.cursor()) as cr: + cr.execute(query) + def set_job_enqueued(self, uuid): with closing(self.conn.cursor()) as cr: cr.execute("UPDATE queue_job SET state=%s, " @@ -408,6 +413,12 @@ def run_jobs(self): def process_notifications(self): for db in self.db_by_name.values(): + if not db.conn.notifies: + # If there are no activity in the queue_job table it seems that + # tcp keepalives are not sent (in that very specific scenario), + # causing some intermediaries (such as haproxy) to close the + # connection, making the jobrunner to restart on a socket error + db.keep_alive() while db.conn.notifies: if self._stop: break diff --git a/queue_job/readme/CONTRIBUTORS.rst b/queue_job/readme/CONTRIBUTORS.rst index 63d1d390a4..e049f26f52 100644 --- a/queue_job/readme/CONTRIBUTORS.rst +++ b/queue_job/readme/CONTRIBUTORS.rst @@ -6,3 +6,5 @@ * Laurent Mignon * Laetitia Gangloff * Cédric Pigeon +* Souheil Bejaoui +* Georg A. G. Notter