Skip to content

Commit 98e4448

Browse files
committed
Convert job ID to UUID
In some CI runs it was observed that unexpected results were being returned for middleware jobs. This commit converts our job ids from being monotonically incrementing integer to proper uuid so that the job id that client is trying to track is guaranteed to uniquely identify it regardless of which HA node is being connected to.
1 parent 4f404a5 commit 98e4448

File tree

1 file changed

+3
-8
lines changed
  • src/middlewared/middlewared

1 file changed

+3
-8
lines changed

src/middlewared/middlewared/job.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import contextlib
3-
from collections import OrderedDict
43
import copy
54
import enum
65
import errno
@@ -17,6 +16,7 @@
1716
from middlewared.pipe import Pipes
1817
from middlewared.utils.privilege import credential_is_limited_to_own_jobs, credential_has_full_admin
1918
from middlewared.utils.time_utils import utc_now
19+
from uuid import uuid4
2020

2121

2222
logger = logging.getLogger(__name__)
@@ -225,8 +225,7 @@ class JobsDeque:
225225

226226
def __init__(self, maxlen=1000):
227227
self.maxlen = maxlen
228-
self.count = 0
229-
self.__dict = OrderedDict()
228+
self.__dict = {}
230229
with contextlib.suppress(FileNotFoundError):
231230
shutil.rmtree(LOGS_DIR)
232231

@@ -244,7 +243,6 @@ def _get_next_id(self):
244243
return self.count
245244

246245
def add(self, job):
247-
job.set_id(self._get_next_id())
248246
if len(self.__dict) > self.maxlen:
249247
for old_job_id, old_job in self.__dict.items():
250248
if old_job.state in (State.SUCCESS, State.FAILED, State.ABORTED):
@@ -291,7 +289,7 @@ def __init__(self, middleware, method_name, serviceobj, method, args, options, p
291289
self.app = app
292290
self.audit_callback = audit_callback
293291

294-
self.id = None
292+
self.id = int(uuid4())
295293
self.lock = None
296294
self.result = None
297295
self.error = None
@@ -377,9 +375,6 @@ def get_lock_name(self):
377375
errno.EINVAL)
378376
return lock_name
379377

380-
def set_id(self, id_):
381-
self.id = id_
382-
383378
def set_result(self, result):
384379
self.result = result
385380

0 commit comments

Comments
 (0)