diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 85996b98f3..afd28d2ad5 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -321,6 +321,11 @@ def select_jobs(self, where, args): cr.execute(query, args) yield cr + 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( @@ -433,6 +438,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 46215f69cf..9694c9654a 100644 --- a/queue_job/readme/CONTRIBUTORS.rst +++ b/queue_job/readme/CONTRIBUTORS.rst @@ -7,3 +7,4 @@ * Laetitia Gangloff * Cédric Pigeon * Tatiana Deribina +* Souheil Bejaoui