2121)
2222
2323from opentelemetry import trace
24- from uuid_extensions import uuid7
24+ from uuid_extensions import uuid7 # type: ignore[import-untyped]
2525
2626from .backends import Backend , RedisBackend
2727from .execution import (
@@ -95,9 +95,9 @@ async def my_task(greeting: str, recipient: str) -> None:
9595
9696 tasks : dict [str , TaskFunction ]
9797 strike_list : StrikeList
98+ backend : Backend
9899
99100 _monitor_strikes_task : asyncio .Task [None ]
100- _backend : Backend
101101
102102 def __init__ (
103103 self ,
@@ -124,7 +124,7 @@ def __init__(
124124 self .heartbeat_interval = heartbeat_interval
125125 self .missed_heartbeats = missed_heartbeats
126126 # Create backend based on URL scheme
127- self ._backend = RedisBackend (name , url )
127+ self .backend = RedisBackend (name , url )
128128
129129 @property
130130 def worker_group_name (self ) -> str :
@@ -136,7 +136,7 @@ async def __aenter__(self) -> Self:
136136 self .tasks = {fn .__name__ : fn for fn in standard_tasks }
137137 self .strike_list = StrikeList ()
138138
139- await self ._backend .initialize ()
139+ await self .backend .initialize ()
140140 self ._monitor_strikes_task = asyncio .create_task (self ._monitor_strikes ())
141141
142142 return self
@@ -159,7 +159,7 @@ async def __aexit__(
159159 except asyncio .CancelledError :
160160 pass
161161
162- await self ._backend .close ()
162+ await self .backend .close ()
163163
164164 def register (self , function : TaskFunction ) -> None :
165165 """Register a task with the Docket.
@@ -265,7 +265,7 @@ async def scheduler(*args: P.args, **kwargs: P.kwargs) -> Execution:
265265 )
266266 return execution
267267
268- await self ._backend .schedule_task (execution , replace = False )
268+ await self .backend .schedule_task (execution , replace = False )
269269
270270 TASKS_ADDED .add (1 , {** self .labels (), ** execution .general_labels ()})
271271 TASKS_SCHEDULED .add (1 , {** self .labels (), ** execution .general_labels ()})
@@ -340,7 +340,7 @@ async def scheduler(*args: P.args, **kwargs: P.kwargs) -> Execution:
340340 )
341341 return execution
342342
343- await self ._backend .schedule_task (execution , replace = True )
343+ await self .backend .schedule_task (execution , replace = True )
344344
345345 TASKS_REPLACED .add (1 , {** self .labels (), ** execution .general_labels ()})
346346 TASKS_CANCELLED .add (1 , {** self .labels (), ** execution .general_labels ()})
@@ -376,7 +376,7 @@ async def schedule(self, execution: Execution) -> None:
376376 "code.function.name" : execution .function .__name__ ,
377377 },
378378 ):
379- await self ._backend .schedule_task (execution , replace = False )
379+ await self .backend .schedule_task (execution , replace = False )
380380
381381 TASKS_SCHEDULED .add (1 , {** self .labels (), ** execution .general_labels ()})
382382
@@ -390,30 +390,30 @@ async def cancel(self, key: str) -> None:
390390 "docket.cancel" ,
391391 attributes = {** self .labels (), "docket.key" : key },
392392 ):
393- await self ._backend .cancel_task (key )
393+ await self .backend .cancel_task (key )
394394
395395 TASKS_CANCELLED .add (1 , self .labels ())
396396
397397 @property
398398 def queue_key (self ) -> str :
399- return self ._backend .queue_key
399+ return self .backend .queue_key
400400
401401 @property
402402 def stream_key (self ) -> str :
403- return self ._backend .stream_key
403+ return self .backend .stream_key
404404
405405 def known_task_key (self , key : str ) -> str :
406- return self ._backend .known_task_key (key )
406+ return self .backend .known_task_key (key )
407407
408408 def parked_task_key (self , key : str ) -> str :
409- return self ._backend .parked_task_key (key )
409+ return self .backend .parked_task_key (key )
410410
411411 def stream_id_key (self , key : str ) -> str :
412- return self ._backend .stream_id_key (key )
412+ return self .backend .stream_id_key (key )
413413
414414 @property
415415 def strike_key (self ) -> str :
416- return self ._backend .strike_key
416+ return self .backend .strike_key
417417
418418 async def strike (
419419 self ,
@@ -469,14 +469,14 @@ async def _send_strike_instruction(self, instruction: StrikeInstruction) -> None
469469 ** instruction .labels (),
470470 },
471471 ):
472- await self ._backend .send_strike_instruction (instruction )
472+ await self .backend .send_strike_instruction (instruction )
473473 self .strike_list .update (instruction )
474474
475475 async def _monitor_strikes (self ) -> NoReturn :
476476 last_id = "0-0"
477477 while True :
478478 try :
479- instructions = await self ._backend .receive_strike_instructions (
479+ instructions = await self .backend .receive_strike_instructions (
480480 last_id , timeout_ms = 60_000
481481 )
482482 for message_id , instruction in instructions :
@@ -518,7 +518,7 @@ async def snapshot(self) -> DocketSnapshot:
518518 total_tasks ,
519519 future_executions ,
520520 running_executions ,
521- ) = await self ._backend .snapshot (self .tasks )
521+ ) = await self .backend .snapshot (self .tasks )
522522 workers = await self .workers ()
523523
524524 return DocketSnapshot (
@@ -527,13 +527,13 @@ async def snapshot(self) -> DocketSnapshot:
527527
528528 @property
529529 def workers_set (self ) -> str :
530- return self ._backend .workers_set
530+ return self .backend .workers_set
531531
532532 def worker_tasks_set (self , worker_name : str ) -> str :
533- return self ._backend .worker_tasks_set (worker_name )
533+ return self .backend .worker_tasks_set (worker_name )
534534
535535 def task_workers_set (self , task_name : str ) -> str :
536- return self ._backend .task_workers_set (task_name )
536+ return self .backend .task_workers_set (task_name )
537537
538538 async def workers (self ) -> Collection [WorkerInfo ]:
539539 """Get a list of all workers that have sent heartbeats to the Docket.
@@ -544,7 +544,7 @@ async def workers(self) -> Collection[WorkerInfo]:
544544 heartbeat_timeout = (
545545 self .heartbeat_interval .total_seconds () * self .missed_heartbeats
546546 )
547- return await self ._backend .get_workers (heartbeat_timeout )
547+ return await self .backend .get_workers (heartbeat_timeout )
548548
549549 async def task_workers (self , task_name : str ) -> Collection [WorkerInfo ]:
550550 """Get a list of all workers that are able to execute a given task.
@@ -558,7 +558,7 @@ async def task_workers(self, task_name: str) -> Collection[WorkerInfo]:
558558 heartbeat_timeout = (
559559 self .heartbeat_interval .total_seconds () * self .missed_heartbeats
560560 )
561- return await self ._backend .get_task_workers (task_name , heartbeat_timeout )
561+ return await self .backend .get_task_workers (task_name , heartbeat_timeout )
562562
563563 async def clear (self ) -> int :
564564 """Clear all pending and scheduled tasks from the docket.
@@ -574,4 +574,4 @@ async def clear(self) -> int:
574574 "docket.clear" ,
575575 attributes = self .labels (),
576576 ):
577- return await self ._backend .clear ()
577+ return await self .backend .clear ()
0 commit comments