pydocket 0.9.0__py3-none-any.whl → 0.9.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pydocket might be problematic. Click here for more details.

docket/docket.py CHANGED
@@ -428,6 +428,9 @@ class Docket:
428
428
  def parked_task_key(self, key: str) -> str:
429
429
  return f"{self.name}:{key}"
430
430
 
431
+ def stream_id_key(self, key: str) -> str:
432
+ return f"{self.name}:stream-id:{key}"
433
+
431
434
  async def _schedule(
432
435
  self,
433
436
  redis: Redis,
@@ -472,13 +475,14 @@ class Docket:
472
475
  self._schedule_task_script = cast(
473
476
  _schedule_task,
474
477
  redis.register_script(
475
- # KEYS: stream_key, known_key, parked_key, queue_key
478
+ # KEYS: stream_key, known_key, parked_key, queue_key, stream_id_key
476
479
  # ARGV: task_key, when_timestamp, is_immediate, replace, ...message_fields
477
480
  """
478
481
  local stream_key = KEYS[1]
479
482
  local known_key = KEYS[2]
480
483
  local parked_key = KEYS[3]
481
484
  local queue_key = KEYS[4]
485
+ local stream_id_key = KEYS[5]
482
486
 
483
487
  local task_key = ARGV[1]
484
488
  local when_timestamp = ARGV[2]
@@ -494,11 +498,11 @@ class Docket:
494
498
 
495
499
  -- Handle replacement: cancel existing task if needed
496
500
  if replace then
497
- local existing_message_id = redis.call('HGET', known_key, 'stream_message_id')
501
+ local existing_message_id = redis.call('GET', stream_id_key)
498
502
  if existing_message_id then
499
503
  redis.call('XDEL', stream_key, existing_message_id)
500
504
  end
501
- redis.call('DEL', known_key, parked_key)
505
+ redis.call('DEL', known_key, parked_key, stream_id_key)
502
506
  redis.call('ZREM', queue_key, task_key)
503
507
  else
504
508
  -- Check if task already exists
@@ -510,11 +514,12 @@ class Docket:
510
514
  if is_immediate then
511
515
  -- Add to stream and store message ID for later cancellation
512
516
  local message_id = redis.call('XADD', stream_key, '*', unpack(message))
513
- redis.call('HSET', known_key, 'when', when_timestamp, 'stream_message_id', message_id)
517
+ redis.call('SET', known_key, when_timestamp)
518
+ redis.call('SET', stream_id_key, message_id)
514
519
  return message_id
515
520
  else
516
521
  -- Add to queue with task data in parked hash
517
- redis.call('HSET', known_key, 'when', when_timestamp)
522
+ redis.call('SET', known_key, when_timestamp)
518
523
  redis.call('HSET', parked_key, unpack(message))
519
524
  redis.call('ZADD', queue_key, when_timestamp, task_key)
520
525
  return 'QUEUED'
@@ -530,6 +535,7 @@ class Docket:
530
535
  known_task_key,
531
536
  self.parked_task_key(key),
532
537
  self.queue_key,
538
+ self.stream_id_key(key),
533
539
  ],
534
540
  args=[
535
541
  key,
@@ -556,23 +562,24 @@ class Docket:
556
562
  self._cancel_task_script = cast(
557
563
  _cancel_task,
558
564
  redis.register_script(
559
- # KEYS: stream_key, known_key, parked_key, queue_key
565
+ # KEYS: stream_key, known_key, parked_key, queue_key, stream_id_key
560
566
  # ARGV: task_key
561
567
  """
562
568
  local stream_key = KEYS[1]
563
569
  local known_key = KEYS[2]
564
570
  local parked_key = KEYS[3]
565
571
  local queue_key = KEYS[4]
572
+ local stream_id_key = KEYS[5]
566
573
  local task_key = ARGV[1]
567
574
 
568
575
  -- Delete from stream if message ID exists
569
- local message_id = redis.call('HGET', known_key, 'stream_message_id')
576
+ local message_id = redis.call('GET', stream_id_key)
570
577
  if message_id then
571
578
  redis.call('XDEL', stream_key, message_id)
572
579
  end
573
580
 
574
581
  -- Clean up all task-related keys
575
- redis.call('DEL', known_key, parked_key)
582
+ redis.call('DEL', known_key, parked_key, stream_id_key)
576
583
  redis.call('ZREM', queue_key, task_key)
577
584
 
578
585
  return 'OK'
@@ -588,6 +595,7 @@ class Docket:
588
595
  self.known_task_key(key),
589
596
  self.parked_task_key(key),
590
597
  self.queue_key,
598
+ self.stream_id_key(key),
591
599
  ],
592
600
  args=[key],
593
601
  )
@@ -897,6 +905,7 @@ class Docket:
897
905
  key = key_bytes.decode()
898
906
  pipeline.delete(self.parked_task_key(key))
899
907
  pipeline.delete(self.known_task_key(key))
908
+ pipeline.delete(self.stream_id_key(key))
900
909
 
901
910
  await pipeline.execute()
902
911
 
docket/worker.py CHANGED
@@ -406,7 +406,7 @@ class Worker:
406
406
  task[task_data[j]] = task_data[j+1]
407
407
  end
408
408
 
409
- local message_id = redis.call('XADD', KEYS[2], '*',
409
+ redis.call('XADD', KEYS[2], '*',
410
410
  'key', task['key'],
411
411
  'when', task['when'],
412
412
  'function', task['function'],
@@ -414,9 +414,6 @@ class Worker:
414
414
  'kwargs', task['kwargs'],
415
415
  'attempt', task['attempt']
416
416
  )
417
- -- Store the message ID in the known task key
418
- local known_key = ARGV[2] .. ":known:" .. key
419
- redis.call('HSET', known_key, 'stream_message_id', message_id)
420
417
  redis.call('DEL', hash_key)
421
418
  due_work = due_work + 1
422
419
  end
@@ -498,7 +495,8 @@ class Worker:
498
495
 
499
496
  logger.debug("Deleting known task", extra=self._log_context())
500
497
  known_task_key = self.docket.known_task_key(key)
501
- await redis.delete(known_task_key)
498
+ stream_id_key = self.docket.stream_id_key(key)
499
+ await redis.delete(known_task_key, stream_id_key)
502
500
 
503
501
  async def _execute(self, execution: Execution) -> None:
504
502
  log_context = {**self._log_context(), **execution.specific_labels()}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydocket
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: A distributed background task system for Python functions
5
5
  Project-URL: Homepage, https://github.com/chrisguidry/docket
6
6
  Project-URL: Bug Tracker, https://github.com/chrisguidry/docket/issues
@@ -3,14 +3,14 @@ docket/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
3
3
  docket/annotations.py,sha256=wttix9UOeMFMAWXAIJUfUw5GjESJZsACb4YXJCozP7Q,2348
4
4
  docket/cli.py,sha256=rTfri2--u4Q5PlXyh7Ub_F5uh3-TtZOWLUp9WY_TvAE,25750
5
5
  docket/dependencies.py,sha256=BC0bnt10cr9_S1p5JAP_bnC9RwZkTr9ulPBrxC7eZnA,20247
6
- docket/docket.py,sha256=0nQCHDDHy7trv2a0eYygGgIKiA7fWq5GcOXye3_CPWM,30847
6
+ docket/docket.py,sha256=jP5uI02in5chQvovRsnPaMhgLff3uiK42A-l3eBh2sE,31241
7
7
  docket/execution.py,sha256=r_2RGC1qhtAcBUg7E6wewLEgftrf3hIxNbH0HnYPbek,14961
8
8
  docket/instrumentation.py,sha256=ogvzrfKbWsdPGfdg4hByH3_r5d3b5AwwQkSrmXw0hRg,5492
9
9
  docket/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  docket/tasks.py,sha256=RIlSM2omh-YDwVnCz6M5MtmK8T_m_s1w2OlRRxDUs6A,1437
11
- docket/worker.py,sha256=jqVYqtQyxbk-BIy3shY8haX-amVT9Np97VhJuaQTfpM,35174
12
- pydocket-0.9.0.dist-info/METADATA,sha256=kymp9PKG7UwMj0i0qGSSCHKu-g-tS__qydr6mYuMLtg,5418
13
- pydocket-0.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- pydocket-0.9.0.dist-info/entry_points.txt,sha256=4WOk1nUlBsUT5O3RyMci2ImuC5XFswuopElYcLHtD5k,47
15
- pydocket-0.9.0.dist-info/licenses/LICENSE,sha256=YuVWU_ZXO0K_k2FG8xWKe5RGxV24AhJKTvQmKfqXuyk,1087
16
- pydocket-0.9.0.dist-info/RECORD,,
11
+ docket/worker.py,sha256=S5HG87vHa_r1JKApHpEtNkVdUhkdi802zUw3h_zIHt0,34998
12
+ pydocket-0.9.2.dist-info/METADATA,sha256=gWX-2gIAQ5pn3fQ1XwFweQYnbXwsgIpGVahW7KJJNtU,5418
13
+ pydocket-0.9.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ pydocket-0.9.2.dist-info/entry_points.txt,sha256=4WOk1nUlBsUT5O3RyMci2ImuC5XFswuopElYcLHtD5k,47
15
+ pydocket-0.9.2.dist-info/licenses/LICENSE,sha256=YuVWU_ZXO0K_k2FG8xWKe5RGxV24AhJKTvQmKfqXuyk,1087
16
+ pydocket-0.9.2.dist-info/RECORD,,