abstract-block-dumper 0.0.4__py3-none-any.whl → 0.0.6__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.
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.4'
32
- __version_tuple__ = version_tuple = (0, 0, 4)
31
+ __version__ = version = '0.0.6'
32
+ __version_tuple__ = version_tuple = (0, 0, 6)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -134,24 +134,39 @@ def _celery_task_wrapper(
134
134
 
135
135
 
136
136
  def block_task(
137
- condition: Callable[..., bool],
137
+ func: Callable[..., Any] | None = None,
138
+ *,
139
+ condition: Callable[..., bool] | None = None,
138
140
  args: list[dict[str, Any]] | None = None,
139
141
  backfilling_lookback: int | None = None,
140
142
  celery_kwargs: dict[str, Any] | None = None,
141
143
  ) -> Callable[..., Any]:
142
144
  """
143
- Register a block task.
145
+ Decorator to register a function as a block task.
146
+
147
+ Block task is a function that will be executed conditionally on each new block.
148
+ The condition is a callable that takes the block number and any additional arguments,
149
+ and returns a boolean indicating whether to execute the task.
144
150
 
145
151
  Args:
146
- condition: Lambda function that determines when to execute
152
+ func: The function to decorate (used when decorator is applied without parentheses)
153
+ condition: Lambda function that determines when to execute the task. It should accept
154
+ block_number and any additional args as parameters and return a boolean.
155
+ Defaults to always True (run on every block).
147
156
  args: List of argument dictionaries for multi-execution
148
157
  backfilling_lookback: Number of blocks to backfill
149
158
  celery_kwargs: Additional Celery task parameters
150
159
 
151
160
  Examples:
152
- @block_task(
153
- condition=lambda bn: bn % 100 == 0
154
- )
161
+ @block_task
162
+ def run_on_every_block(block_number: int):
163
+ pass
164
+
165
+ @block_task()
166
+ def also_runs_on_every_block(block_number: int):
167
+ pass
168
+
169
+ @block_task(condition=lambda bn: bn % 100 == 0)
155
170
  def simple_task(block_number: int):
156
171
  pass
157
172
 
@@ -165,9 +180,11 @@ def block_task(
165
180
  pass
166
181
 
167
182
  """
183
+ # Default condition: always run
184
+ effective_condition = condition if condition is not None else (lambda *_args, **_kwargs: True)
168
185
 
169
- def decorator(func: Callable[..., Any]) -> Any:
170
- if not callable(condition):
186
+ def decorator(fn: Callable[..., Any]) -> Any:
187
+ if not callable(effective_condition):
171
188
  msg = "condition must be a callable."
172
189
  raise TypeError(msg)
173
190
 
@@ -179,22 +196,22 @@ def block_task(
179
196
 
180
197
  This entire wrapper becomes a Celery task.
181
198
  """
182
- return _celery_task_wrapper(func, block_number, **kwargs)
199
+ return _celery_task_wrapper(fn, block_number, **kwargs)
183
200
 
184
201
  # Wrap with celery shared_task
185
202
  celery_task = shared_task(
186
- name=abd_utils.get_executable_path(func),
203
+ name=abd_utils.get_executable_path(fn),
187
204
  bind=False,
188
205
  **celery_kwargs or {},
189
206
  )(shared_celery_task)
190
207
 
191
208
  # Store original function referefence for introspection
192
- celery_task._original_func = func # noqa: SLF001
209
+ celery_task._original_func = fn # noqa: SLF001
193
210
 
194
211
  # Register the Celery task
195
212
  task_registry.register_item(
196
213
  RegistryItem(
197
- condition=condition,
214
+ condition=effective_condition,
198
215
  function=cast("Task", celery_task),
199
216
  args=args,
200
217
  backfilling_lookback=backfilling_lookback,
@@ -203,4 +220,9 @@ def block_task(
203
220
  )
204
221
  return celery_task
205
222
 
223
+ # If func is provided, decorator was used without parentheses: @block_task
224
+ if func is not None:
225
+ return decorator(func)
226
+
227
+ # Otherwise, decorator was used with parentheses: @block_task() or @block_task(condition=...)
206
228
  return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract-block-dumper
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Project-URL: Source, https://github.com/bactensor/abstract-block-dumper
5
5
  Project-URL: Issue Tracker, https://github.com/bactensor/abstract-block-dumper/issues
6
6
  Author-email: Reef Technologies <opensource@reef.pl>
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Topic :: Software Development :: Libraries
16
16
  Requires-Python: >=3.11
17
17
  Requires-Dist: bittensor>=9.10.1
18
- Requires-Dist: celery>=5.5.3
18
+ Requires-Dist: celery>=5.3
19
19
  Requires-Dist: django<6.0,>=3.2
20
20
  Requires-Dist: structlog>=25.4.0
21
21
  Description-Content-Type: text/markdown
@@ -104,18 +104,21 @@ In your project's `celery.py` file, add the following to ensure Celery workers c
104
104
 
105
105
  ```python
106
106
  from celery import Celery
107
- from celery.signals import worker_ready
107
+ from celery.signals import celeryd_init
108
108
  from django.conf import settings
109
109
 
110
110
  app = Celery('your_project')
111
111
  app.config_from_object('django.conf:settings', namespace='CELERY')
112
112
  app.autodiscover_tasks()
113
113
 
114
- @worker_ready.connect
115
- def on_worker_ready(**kwargs):
116
- """Load block tasks when worker starts."""
114
+
115
+
116
+ @celeryd_init.connect
117
+ def on_worker_init(**kwargs) -> None:
118
+ """Load block tasks when worker initializes."""
117
119
  from abstract_block_dumper.v1.celery import setup_celery_tasks
118
120
  setup_celery_tasks()
121
+
119
122
  ```
120
123
 
121
124
  > **Important:** Without this step, Celery workers will not recognize your `@block_task` decorated functions, and you'll see "Received unregistered task" errors.
@@ -154,7 +157,7 @@ from abstract_block_dumper.v1.decorators import block_task
154
157
 
155
158
 
156
159
  # Process every block
157
- @block_task(condition=lambda bn: True)
160
+ @block_task
158
161
  def process_every_block(block_number: int):
159
162
  print(f"Processing every block: {block_number}")
160
163
 
@@ -1,5 +1,5 @@
1
1
  abstract_block_dumper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- abstract_block_dumper/_version.py,sha256=QlXZ5JTjE_pgpDaeHk0GTExkc75xUZFmd0hA7kGYCJ0,704
2
+ abstract_block_dumper/_version.py,sha256=7MyqQ3iPP2mJruPfRYGCNCq1z7_Nk7c-eyYecYITxsY,704
3
3
  abstract_block_dumper/admin.py,sha256=3J3I_QOKFgfMNpTXW-rTQGO_q5Ls6uNuL0FkPVdIsYg,1654
4
4
  abstract_block_dumper/apps.py,sha256=DXATdrjsL3T2IletTbKeD6unr8ScLaxg7wz0nAHTAns,215
5
5
  abstract_block_dumper/models.py,sha256=MO9824dmHB6xF3PrFE_RERh7whVjQtS4tt6QA0wSbg0,2022
@@ -22,8 +22,8 @@ abstract_block_dumper/migrations/0001_initial.py,sha256=ImPHC3G6kPkq4Xn_4YVAm4La
22
22
  abstract_block_dumper/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  abstract_block_dumper/v1/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  abstract_block_dumper/v1/celery.py,sha256=X4IqVs5i6ZpyY7fy1SqMZgsZy4SXP-jK2qG-FYnjU38,1722
25
- abstract_block_dumper/v1/decorators.py,sha256=i-CVanS-yiBMKCEOLjGmwmopefWePhyMdodlWNIfJFg,7002
25
+ abstract_block_dumper/v1/decorators.py,sha256=SBl8XP9qhKyTdsKaRREW870BZGidEe0C_nmxnwh76lo,8156
26
26
  abstract_block_dumper/v1/tasks.py,sha256=u9iMYdDUqzYT3yPrNwZecHnlweZ3yFipV9BcIWHCbus,2647
27
- abstract_block_dumper-0.0.4.dist-info/METADATA,sha256=wBsIWl5439xp-EYInzV-mQaAKIoa_CDP97FJoeaB-ng,12916
28
- abstract_block_dumper-0.0.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- abstract_block_dumper-0.0.4.dist-info/RECORD,,
27
+ abstract_block_dumper-0.0.6.dist-info/METADATA,sha256=yXyU72VareEjcSb8A4Tur5hWkgk5k6lBLy9cnqR--kY,12902
28
+ abstract_block_dumper-0.0.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ abstract_block_dumper-0.0.6.dist-info/RECORD,,