Skip to content

Commit

Permalink
Merge pull request #1217 from openradx/fix-periodic-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Oct 8, 2024
2 parents 48b4ee9 + e56a5ce commit 3ebbe2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion procrastinate/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SELECT procrastinate_defer_job(%(queue)s, %(task_name)s, %(priority)s, %(lock)s,
-- defer_periodic_job --
-- Create a periodic job if it doesn't already exist, and delete periodic metadata
-- for previous jobs in the same task.
SELECT procrastinate_defer_periodic_job(%(queue)s, %(lock)s, %(queueing_lock)s, %(task_name)s, %(periodic_id)s, %(defer_timestamp)s, %(args)s) AS id;
SELECT procrastinate_defer_periodic_job(%(queue)s, %(lock)s, %(queueing_lock)s, %(task_name)s, %(priority)s, %(periodic_id)s, %(defer_timestamp)s, %(args)s) AS id;

-- fetch_job --
-- Get the first awaiting job
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def sleep_and_write(sleep, write_before, write_after):


@cron_app.periodic(cron="* * * * * *")
@cron_app.task()
def tick(timestamp):
print("tick", next(counter), timestamp)
@cron_app.task(priority=7, pass_context=True)
def tick(context, timestamp):
print("tick", next(counter), context.job.priority, timestamp)
17 changes: 9 additions & 8 deletions tests/acceptance/test_nominal.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,20 @@ def test_queueing_lock(defer, running_worker):
def test_periodic_deferrer(worker):
# We're launching a worker that executes a periodic task every second, and
# letting it run for 2.5 s. It should execute the task 3 times, and print to stdout:
# 0 <timestamp>
# 1 <timestamp + 1>
# 2 <timestamp + 2> (this one won't always be there)
# 0 <priority> <timestamp>
# 1 <priority> <timestamp + 1>
# 2 <priority> <timestamp + 2> (this one won't always be there)
stdout, stderr = worker(app="cron_app", sleep=3)
# This won't be visible unless the test fails
print(stdout)
print(stderr)

# We're making a dict from the output
results = dict(
(int(a) for a in e[5:].split())
results = [
[int(a) for a in e[5:].split()]
for e in stdout.splitlines()
if e.startswith("tick ")
)
assert list(results)[:2] == [0, 1]
assert results[1] == results[0] + 1
]
assert [row[0] for row in results][:2] == [0, 1]
assert [row[1] for row in results][:2] == [7, 7]
assert results[1][2] == results[0][2] + 1

0 comments on commit 3ebbe2b

Please sign in to comment.