Skip to content

Commit

Permalink
Add auto_calculate_deadline attribute to Scheduler (#3869)
Browse files Browse the repository at this point in the history
Co-authored-by: Rieven <[email protected]>
Co-authored-by: Jan Klopper <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent f3c0482 commit 413ffe5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion mula/scheduler/schedulers/boefje.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ def __init__(
pq_store=ctx.datastores.pq_store,
)

super().__init__(ctx=ctx, queue=self.queue, scheduler_id=scheduler_id, callback=callback, create_schedule=True)
super().__init__(
ctx=ctx,
queue=self.queue,
scheduler_id=scheduler_id,
callback=callback,
create_schedule=True,
auto_calculate_deadline=True,
)

# Priority ranker
self.priority_ranker = rankers.BoefjeRanker(self.ctx)
Expand Down
10 changes: 8 additions & 2 deletions mula/scheduler/schedulers/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(
):
self.logger: structlog.BoundLogger = structlog.getLogger(__name__)
self.organisation: Organisation = organisation
self.create_schedule = False

self.queue = queue or queues.PriorityQueue(
pq_id=scheduler_id,
Expand All @@ -48,7 +47,14 @@ def __init__(
pq_store=ctx.datastores.pq_store,
)

super().__init__(ctx=ctx, queue=self.queue, scheduler_id=scheduler_id, callback=callback)
super().__init__(
ctx=ctx,
queue=self.queue,
scheduler_id=scheduler_id,
callback=callback,
create_schedule=False,
auto_calculate_deadline=False,
)

self.ranker = rankers.NormalizerRanker(ctx=self.ctx)

Expand Down
9 changes: 8 additions & 1 deletion mula/scheduler/schedulers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ def __init__(
pq_store=ctx.datastores.pq_store,
)

super().__init__(ctx=ctx, queue=self.queue, scheduler_id=scheduler_id, callback=callback, create_schedule=True)
super().__init__(
ctx=ctx,
queue=self.queue,
scheduler_id=scheduler_id,
callback=callback,
create_schedule=True,
auto_calculate_deadline=False,
)

def run(self) -> None:
# Rescheduling
Expand Down
4 changes: 3 additions & 1 deletion mula/scheduler/schedulers/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(
callback: Callable[..., None] | None = None,
max_tries: int = -1,
create_schedule: bool = False,
auto_calculate_deadline: bool = True,
):
"""Initialize the Scheduler.
Expand Down Expand Up @@ -88,6 +89,7 @@ def __init__(
self.max_tries: int = max_tries
self.enabled: bool = True
self.create_schedule: bool = create_schedule
self.auto_calculate_deadline: bool = auto_calculate_deadline
self._last_activity: datetime | None = None

# Queue
Expand Down Expand Up @@ -327,7 +329,7 @@ def post_push(self, item: models.Task) -> models.Task:
# based on the item.
if schedule_db.schedule is not None:
schedule_db.deadline_at = cron.next_run(schedule_db.schedule)
else:
elif self.auto_calculate_deadline:
schedule_db.deadline_at = self.calculate_deadline(item)

self.ctx.datastores.schedule_store.update_schedule(schedule_db)
Expand Down

0 comments on commit 413ffe5

Please sign in to comment.