From 6f0e1f34dc03560a4e6291f1e714d3b096750673 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 2 Mar 2020 17:15:31 +0530 Subject: [PATCH] fix(rq): randomize worker name with uuid fixes issue with rq where worker with the same name already exists. cases where a pid gets killed and is respawned with the same pid, when the worker isn't dead and a new worker is being spawned; causes the following error: ValueError: There exists an active worker named u'xxxxxxxxxxxx.y' already fixed by appending random hex uuid for every worker. inspo: https://github.com/rq/rq/blob/master/rq/worker.py#L187 Signed-off-by: Chinmay D. Pai --- frappe/utils/background_jobs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/utils/background_jobs.py b/frappe/utils/background_jobs.py index 65b2326733..11c710626b 100755 --- a/frappe/utils/background_jobs.py +++ b/frappe/utils/background_jobs.py @@ -8,6 +8,7 @@ import frappe import os, socket, time from frappe import _ from six import string_types +from uuid import uuid4 # imports - third-party imports @@ -152,7 +153,8 @@ def get_worker_name(queue): if queue: # hostname.pid is the default worker name - name = '{hostname}.{pid}.{queue}'.format( + name = '{uuid}.{hostname}.{pid}.{queue}'.format( + uuid=uuid4().hex, hostname=socket.gethostname(), pid=os.getpid(), queue=queue)