Skip to content

Commit

Permalink
Limit requesting prior tasks for ranking in scheduler (#3836)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Klopper <[email protected]>
  • Loading branch information
jpbruinsslot and underdarknl authored Nov 21, 2024
1 parent aae4cb3 commit 1d1cfb5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions mula/scheduler/rankers/boefje.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def rank(self, obj: Any) -> int:
grace_period = timedelta(seconds=self.ctx.config.pq_grace_period)

# New tasks that have not yet run before
if obj.prior_tasks is None or not obj.prior_tasks:
if obj.latest_task is None or not obj.latest_task:
return 2

# Make sure that we don't have tasks that are still in the grace period
time_since_grace_period = ((datetime.now(timezone.utc) - obj.prior_tasks[0].modified_at) - grace_period).seconds
time_since_grace_period = ((datetime.now(timezone.utc) - obj.latest_task.modified_at) - grace_period).seconds
if time_since_grace_period < 0:
return -1

Expand Down
4 changes: 2 additions & 2 deletions mula/scheduler/schedulers/boefje.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def push_boefje_task(self, boefje_task: BoefjeTask, caller: str = "") -> None:
)
return

prior_tasks = self.ctx.datastores.task_store.get_tasks_by_hash(boefje_task.hash)
score = self.priority_ranker.rank(SimpleNamespace(prior_tasks=prior_tasks, task=boefje_task))
latest_task = self.ctx.datastores.task_store.get_latest_task_by_hash(boefje_task.hash)
score = self.priority_ranker.rank(SimpleNamespace(latest_task=latest_task, task=boefje_task))

task = Task(
id=boefje_task.id,
Expand Down
6 changes: 3 additions & 3 deletions mula/tests/integration/test_boefje_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,10 @@ def test_push_task_no_ooi(self):
@mock.patch("scheduler.schedulers.BoefjeScheduler.has_boefje_permission_to_run")
@mock.patch("scheduler.schedulers.BoefjeScheduler.has_boefje_task_grace_period_passed")
@mock.patch("scheduler.schedulers.BoefjeScheduler.is_item_on_queue_by_hash")
@mock.patch("scheduler.context.AppContext.datastores.task_store.get_tasks_by_hash")
@mock.patch("scheduler.context.AppContext.datastores.task_store.get_latest_task_by_hash")
def test_push_task_queue_full(
self,
mock_get_tasks_by_hash,
mock_get_latest_task_by_hash,
mock_is_item_on_queue_by_hash,
mock_has_boefje_task_grace_period_passed,
mock_has_boefje_permission_to_run,
Expand All @@ -606,7 +606,7 @@ def test_push_task_queue_full(
mock_has_boefje_task_started_running.return_value = False
mock_has_boefje_task_grace_period_passed.return_value = True
mock_is_item_on_queue_by_hash.return_value = False
mock_get_tasks_by_hash.return_value = None
mock_get_latest_task_by_hash.return_value = None
self.mock_get_plugin.return_value = PluginFactory(scan_level=0, consumes=[ooi.object_type])

# Act
Expand Down

0 comments on commit 1d1cfb5

Please sign in to comment.