kicker 1.4.2__tar.gz → 1.4.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: kicker
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: Lightweight job runner framework built on FastAPI and APScheduler with a simple web UI.
5
5
  Author: Andrey Morozov
6
6
  Author-email: Andrey Morozov <andrey@morozov.lv>
@@ -191,6 +191,17 @@ app.include_coworker(worker) # default instance
191
191
  app.include_coworker(worker, instance="v2")
192
192
  ```
193
193
 
194
+ It is also possible to specify different schedules for the same worker:
195
+
196
+ ```python
197
+ from kicker import Kicker
198
+ from jobs.weekly_report import worker
199
+
200
+ app = Kicker()
201
+ app.include_coworker(worker, second="*/6")
202
+ app.include_coworker(worker, instance="v2", second="*/4")
203
+ ```
204
+
194
205
  or just directly in the job decorator:
195
206
 
196
207
  ```python
@@ -307,7 +318,7 @@ async def test_db_access(ctx: JobContext):
307
318
  ctx.logger.error(f"Error occurred: {e}")
308
319
  ```
309
320
 
310
- Various event handlers
321
+ ## Various event handlers
311
322
 
312
323
  ```python
313
324
  from kicker import Coworker, JobContext
@@ -324,7 +335,7 @@ async def on_system_shutdown(ctx: JobContext):
324
335
  @worker.kick(second="*/6",
325
336
  on_shutdown_requested=on_system_shutdown,
326
337
  on_job_paused=on_paused)
327
- async def test_on_pause(ctx: JobContext):
338
+ async def test_event_handlers(ctx: JobContext):
328
339
  ctx.logger.info("I'm working!")
329
340
  ```
330
341
 
@@ -176,6 +176,17 @@ app.include_coworker(worker) # default instance
176
176
  app.include_coworker(worker, instance="v2")
177
177
  ```
178
178
 
179
+ It is also possible to specify different schedules for the same worker:
180
+
181
+ ```python
182
+ from kicker import Kicker
183
+ from jobs.weekly_report import worker
184
+
185
+ app = Kicker()
186
+ app.include_coworker(worker, second="*/6")
187
+ app.include_coworker(worker, instance="v2", second="*/4")
188
+ ```
189
+
179
190
  or just directly in the job decorator:
180
191
 
181
192
  ```python
@@ -292,7 +303,7 @@ async def test_db_access(ctx: JobContext):
292
303
  ctx.logger.error(f"Error occurred: {e}")
293
304
  ```
294
305
 
295
- Various event handlers
306
+ ## Various event handlers
296
307
 
297
308
  ```python
298
309
  from kicker import Coworker, JobContext
@@ -309,7 +320,7 @@ async def on_system_shutdown(ctx: JobContext):
309
320
  @worker.kick(second="*/6",
310
321
  on_shutdown_requested=on_system_shutdown,
311
322
  on_job_paused=on_paused)
312
- async def test_on_pause(ctx: JobContext):
323
+ async def test_event_handlers(ctx: JobContext):
313
324
  ctx.logger.info("I'm working!")
314
325
  ```
315
326
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kicker"
3
- version = "1.4.2"
3
+ version = "1.4.4"
4
4
  description = "Lightweight job runner framework built on FastAPI and APScheduler with a simple web UI."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -55,7 +55,16 @@ class Coworker:
55
55
  **schedule,
56
56
  ):
57
57
  def decorator(func):
58
- self._jobs.append(JobSpec(func, schedule, instance, lifespan, on_shutdown_requested, on_job_paused))
58
+ self._jobs.append(
59
+ JobSpec(
60
+ func,
61
+ schedule,
62
+ instance,
63
+ lifespan,
64
+ on_shutdown_requested,
65
+ on_job_paused,
66
+ )
67
+ )
59
68
  return func
60
69
 
61
70
  return decorator
@@ -74,7 +83,9 @@ class Kicker(Coworker, FastAPI):
74
83
  ):
75
84
  self._running_jobs: set[str] = set()
76
85
  self._paused_jobs: dict[str, datetime] = {}
77
- self._on_job_paused_registrations: dict[str, Tuple[JobContextCallback, JobContext]] = {}
86
+ self._on_job_paused_registrations: dict[
87
+ str, Tuple[JobContextCallback, JobContext]
88
+ ] = {}
78
89
  self._job_runs_counter: dict[str, int] = {}
79
90
  self._job_last_execution_status: dict[str, tuple[ExecutionStatus, int]] = {}
80
91
  _default_key = "default"
@@ -102,14 +113,13 @@ class Kicker(Coworker, FastAPI):
102
113
 
103
114
  if inspect.iscoroutinefunction(func):
104
115
  return bound
105
- else:
106
116
 
107
- @wraps(func)
108
- async def wrapper(*args):
109
- loop = asyncio.get_running_loop()
110
- return await loop.run_in_executor(None, bound, *args)
117
+ @wraps(func)
118
+ async def wrapper(*args):
119
+ loop = asyncio.get_running_loop()
120
+ return await loop.run_in_executor(None, bound, *args)
111
121
 
112
- return wrapper
122
+ return wrapper
113
123
 
114
124
  @asynccontextmanager
115
125
  async def _lifespan(fast_api: FastAPI):
@@ -156,7 +166,10 @@ class Kicker(Coworker, FastAPI):
156
166
  on_shutdown_requests.append((job.on_shutdown_requested, ctx))
157
167
 
158
168
  if job.on_job_paused is not None:
159
- self._on_job_paused_registrations[job_id] = (job.on_job_paused, ctx)
169
+ self._on_job_paused_registrations[job_id] = (
170
+ job.on_job_paused,
171
+ ctx,
172
+ )
160
173
 
161
174
  wrapper = _wrap_job(
162
175
  job.func,
@@ -173,12 +186,13 @@ class Kicker(Coworker, FastAPI):
173
186
 
174
187
  yield
175
188
  finally:
176
-
177
189
  if self.scheduler.running:
178
190
  self.scheduler.pause()
179
191
 
180
192
  for on_shutdown_request, ctx in on_shutdown_requests:
181
- self.system_logger.debug("Running job on_shutdown_request for %s", ctx.job_id)
193
+ self.system_logger.debug(
194
+ "Running job on_shutdown_request for %s", ctx.job_id
195
+ )
182
196
  try:
183
197
  if inspect.iscoroutinefunction(on_shutdown_request):
184
198
  await on_shutdown_request(ctx)
@@ -191,7 +205,6 @@ class Kicker(Coworker, FastAPI):
191
205
  "Job on_shutdown_request failed for %s", ctx.job_id
192
206
  )
193
207
 
194
-
195
208
  try:
196
209
  if self.scheduler.running:
197
210
  while self._running_jobs:
@@ -199,7 +212,6 @@ class Kicker(Coworker, FastAPI):
199
212
  except Exception:
200
213
  self.system_logger.exception("Failed to wait for running jobs")
201
214
 
202
-
203
215
  try:
204
216
  if self.scheduler.running:
205
217
  self.scheduler.shutdown(wait=True)
@@ -262,15 +274,20 @@ class Kicker(Coworker, FastAPI):
262
274
  lifespan: JobLifespan | None = None,
263
275
  on_shutdown_requested: JobContextCallback | None = None,
264
276
  on_job_paused: JobContextCallback | None = None,
277
+ **schedule,
265
278
  ):
266
279
  self._jobs.extend(
267
280
  JobSpec(
268
281
  func=job.func,
269
- schedule=job.schedule,
282
+ schedule=dict(schedule or job.schedule),
270
283
  instance=instance if instance is not None else job.instance,
271
- lifespan=(job.lifespan if job.lifespan is not None else lifespan),
272
- on_shutdown_requested=(job.on_shutdown_requested if job.on_shutdown_requested is not None else on_shutdown_requested),
273
- on_job_paused=(job.on_job_paused if job.on_job_paused is not None else on_job_paused),
284
+ lifespan=lifespan if lifespan is not None else job.lifespan,
285
+ on_shutdown_requested=on_shutdown_requested
286
+ if on_shutdown_requested is not None
287
+ else job.on_shutdown_requested,
288
+ on_job_paused=on_job_paused
289
+ if on_job_paused is not None
290
+ else job.on_job_paused,
274
291
  )
275
292
  for job in coworker._jobs
276
293
  )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes