@@ -32,54 +32,52 @@ def delete(self, connection: ConnectionType, job_name: str) -> None:
3232 logger .debug (f"[registry { self ._key } ] Deleting { job_name } " )
3333 connection .zrem (self ._key , job_name )
3434
35+ def exists (self , connection : ConnectionType , job_name : str ) -> bool :
36+ return connection .zrank (self ._key , job_name ) is not None
37+
3538
3639class JobNamesRegistry (ZSetModel ):
3740 _element_key_template : ClassVar [str ] = ":registry:{}"
3841
39- def __init__ (self , connection : ConnectionType , name : str ) -> None :
42+ def __init__ (self , name : str ) -> None :
4043 super ().__init__ (name = name )
41- self .connection = connection
42-
43- def __len__ (self ) -> int :
44- return self .count (self .connection )
45-
46- def __contains__ (self , item : str ) -> bool :
47- return self .connection .zrank (self ._key , item ) is not None
4844
49- def all (self , start : int = 0 , end : int = - 1 ) -> List [str ]:
45+ def all (self , connection : ConnectionType , start : int = 0 , end : int = - 1 ) -> List [str ]:
5046 """Returns a list of all job names.
5147
48+ :param connection: Broker connection
5249 :param start: Start score/timestamp, default to 0.
5350 :param end: End score/timestamp, default to -1 (i.e., no max score).
5451 :returns: Returns a list of all job names with timestamp from start to end
5552 """
56- self .cleanup (self . connection )
57- res = [as_str (job_name ) for job_name in self . connection .zrange (self ._key , start , end )]
58- logger .debug (f"Getting jobs for registry { self ._key } : { len (res )} found." )
53+ self .cleanup (connection )
54+ res = [as_str (job_name ) for job_name in connection .zrange (self ._key , start , end )]
55+ logger .debug (f"Getting jobs for registry { self .key } : { len (res )} found." )
5956 return res
6057
61- def all_with_timestamps (self , start : int = 0 , end : int = - 1 ) -> List [Tuple [str , float ]]:
58+ def all_with_timestamps (self , connection : ConnectionType , start : int = 0 , end : int = - 1 ) -> List [Tuple [str , float ]]:
6259 """Returns a list of all job names with their timestamps.
6360
61+ :param connection: Broker connection
6462 :param start: Start score/timestamp, default to 0.
6563 :param end: End score/timestamp, default to -1 (i.e., no max score).
6664 :returns: Returns a list of all job names with timestamp from start to end
6765 """
68- self .cleanup (self . connection )
69- res = self . connection .zrange (self ._key , start , end , withscores = True )
66+ self .cleanup (connection )
67+ res = connection .zrange (self ._key , start , end , withscores = True )
7068 logger .debug (f"Getting jobs for registry { self ._key } : { len (res )} found." )
7169 return [(as_str (job_name ), timestamp ) for job_name , timestamp in res ]
7270
73- def get_first (self ) -> Optional [str ]:
71+ def get_first (self , connection : ConnectionType ) -> Optional [str ]:
7472 """Returns the first job in the registry."""
75- self .cleanup (self . connection )
76- first_job = self . connection .zrange (self ._key , 0 , 0 )
73+ self .cleanup (connection )
74+ first_job = connection .zrange (self ._key , 0 , 0 )
7775 return first_job [0 ].decode () if first_job else None
7876
79- def get_last_timestamp (self ) -> Optional [int ]:
77+ def get_last_timestamp (self , connection : ConnectionType ) -> Optional [int ]:
8078 """Returns the latest timestamp in the registry."""
81- self .cleanup (self . connection )
82- last_timestamp = self . connection .zrange (self ._key , - 1 , - 1 , withscores = True )
79+ self .cleanup (connection )
80+ last_timestamp = connection .zrange (self ._key , - 1 , - 1 , withscores = True )
8381 return int (last_timestamp [0 ][1 ]) if last_timestamp else None
8482
8583 @property
@@ -88,7 +86,7 @@ def key(self) -> str:
8886
8987 @classmethod
9088 def pop (
91- cls , connection : ConnectionType , registries : Sequence [Self ], timeout : Optional [int ]
89+ cls , connection : ConnectionType , registries : Sequence [Self ], timeout : Optional [int ]
9290 ) -> Tuple [Optional [str ], Optional [str ]]:
9391 """Helper method to abstract away from some Redis API details
9492
0 commit comments