Skip to content

Commit

Permalink
setup result ttl for healthcheck scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Sep 13, 2023
1 parent a9ae756 commit 61cf026
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions runner_manager/jobs/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def bootstrap_healthchecks(
"group": group.name,
},
interval=settings.healthcheck_interval.total_seconds(),
# As described in the documentation of rq-scheduler, the result_ttl
# must be set to a value greater than the interval, otherwise
# the entry job with the details will expire and the job will not get
# rescheduled.
result_ttl=settings.healthcheck_interval.total_seconds() * 10,
repeat=None,
)

Expand Down
7 changes: 5 additions & 2 deletions tests/api/test_lifespan.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from rq import Queue
from rq.job import JobStatus
from rq.job import JobStatus, Job
from starlette.testclient import TestClient

from rq_scheduler import Scheduler

from runner_manager.jobs.startup import startup
from runner_manager.jobs.healthcheck import group


def enqueue_startup(queue: Queue) -> bool:
Expand All @@ -14,7 +17,7 @@ def enqueue_startup(queue: Queue) -> bool:
return False


def test_lifespan(fastapp, queue: Queue):
def test_lifespan(fastapp, queue: Queue, scheduler: Scheduler):
with TestClient(fastapp) as client:
# Application's lifespan is called on entering the block.
response = client.get("/")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/jobs/test_healthchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_need_new_runner_healthcheck(


def test_time_to_start(runner: Runner, settings: Settings):
runner.created_at = datetime.now() - (
runner.created_at = datetime.now(timezone.utc) - (
settings.timeout_runner + timedelta(minutes=1)
)
runner.status = RunnerStatus.offline
Expand Down

0 comments on commit 61cf026

Please sign in to comment.