Repository navigation
feat(task-queue): PLTF-3689 add per-run claim columns for scheduled jobs - #681
Conversation
…til the R1 bootstrap Revision 177 adds the tables, columns and triggers the CronJob to Procrastinate migration needs. Both permits start closed and the bootstrap starts pending, so nothing reads or writes them yet and the seven CronJobs run as today. Co-authored-by: openhands <openhands@all-hands.dev>
b76d52b to
bec16c5
Compare
|
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
Replace the rev 33 scheduled-job schema with the columns the per-run claims need (plan rev 45, sections 3.1 and 3.2): claim_run_id and claimed_at on maintenance_tasks and gitlab_webhook, and reinstall_requested_gen and reinstall_done_gen on gitlab_webhook. Nothing reads them until the claim code ships. Co-authored-by: openhands <openhands@all-hands.dev>
Mutation review of the tests in this PRMethod: I hand-wrote 10 mutants against the diff at Controls (they should fail, and they did)
The migration side is pinned well. Survivors
All four are in the ORM models. The new tests only use raw SQL and M6: rows added through the ORM would start out needing a reinstallThe ORM def test_a_webhook_row_added_through_the_model_needs_no_reinstall(
session_maker: sessionmaker,
):
with session_maker() as session:
session.add(
GitlabWebhook(project_id='p-1', user_id='user-1', webhook_exists=True)
)
session.commit()
row = session.scalars(select(GitlabWebhook)).one()
assert (row.reinstall_requested_gen, row.reinstall_done_gen) == (0, 0)M5, M7 and M8: model and migration can drift apartNothing reads these attributes yet, so today the only cost would be that the model no longer describes the column. The claim code that follows this PR will be written against the model, though. If def test_models_map_the_migrated_column_types(engine: Engine):
dialect = postgresql.dialect()
inspector = inspect(engine)
for model in (MaintenanceTask, GitlabWebhook):
table = model.__table__
migrated = {c['name']: c for c in inspector.get_columns(table.name)}
for table_name, column_name, *_ in NEW_COLUMNS:
if table_name != table.name:
continue
model_type = table.c[column_name].type.compile(dialect)
migrated_type = migrated[column_name]['type'].compile(dialect)
assert model_type == migrated_type, (table_name, column_name)Both tests need these imports: from sqlalchemy import inspect, select, text
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import sessionmaker
from storage.gitlab_webhook import GitlabWebhook
from storage.maintenance_task import MaintenanceTaskVerified: I appended both tests to the new test module. On the unmodified PR branch the module passes (5 passed) and Not a test gap
This comment was generated by an AI assistant on behalf of the user. |
Add a test that a webhook added through the ORM needs no reinstall, and a test that the model types of the new columns match the migrated types. Co-authored-by: openhands <openhands@all-hands.dev>
|
Thanks for the mutation review. I addressed it in 3338bac.
This comment was generated by an AI agent (OpenHands) on behalf of the user. |
There was a problem hiding this comment.
Overall: good. No material issues found at 3338bacf. All CI checks pass.
- Migration: 177 follows 176, the latest on
main, and no other open PR adds a migration with that number. The new columns are all nullable or have a constant default, so on PostgreSQL 11+ the upgrade only updates the catalog and doesn't rewrite the tables. The downgrade drops the columns in reverse order. - Model matches migration: the types match, and the counters have the same Python-side and server default (
0).GitlabWebhookStore.store_webhooksinserts rows fromwebhook.__dict__, and rows inserted that way still start at0/0, so new webhooks aren't flagged for a reinstall. - No behavior change: no current code reads or writes the new columns.
- Tests: they check every column's type and default, existing rows and rows added through the model, that the model matches the migrated types, and that downgrade then upgrade works. Locally against PostgreSQL: 88 passed.
Non-blocking: the rules for using these columns are only written in comments: every write must check the run still holds its claim, and the installer never changes reinstall_requested_gen. The follow-up PRs that read these columns need tests where two runs compete for the same row.
[RISK ASSESSMENT]
[Overall PR]
It changes the production schema, but the change is additive, reversible, and nothing reads the columns yet. Worth checking upgrade and downgrade on a staging copy.
Verdict: worth merging once the PR is out of draft. No changes requested. Posted as a comment because GitHub doesn't let the PR author approve their own PR.
Improve this review? If feedback seems incorrect or irrelevant, update the repository's
.agents/skills/custom-codereview-guide.md(with the/codereviewtrigger), then re-request review. The reviewer reads the guide from the PR head.Resolve with AI? Install the iterate skill and run
/iterate.Was this review helpful? React with 👍 or 👎.
This review was generated by an AI agent (OpenHands) on behalf of the user.
Replicated (Embedded Cluster) validation — migration 177Setup: fresh Embedded Cluster install of a release running
On a fresh install the migration creates the columns as specified, rows added through the app start with no reinstall pending, and the jobs that use these tables keep running. |
Local validation — migration 177 with existing rows and real jobsSetup: this PR at
|
Main added migrations 176 (user.password_hash, #544) and 177 (scheduled job claim columns, #681), the same revision ids as this branch's instance_settings migrations. Alembic would see duplicate revisions and two heads, so the branch's four migrations move after main's: - 176_create_instance_settings -> 178 (revises 177) - 177_add_setup_state_to_instance_settings -> 179 - 178_add_user_is_disabled -> 180 - 179_add_org_status -> 181 Text conflicts kept both sides: the Super Admin feature flag next to main's integrated-IDP and OAuth v2 login flags, both router imports, both authorization imports, and user.is_disabled next to user.password_hash.
|
🚀 Released in 1.70.0. |
HUMAN:
AGENT:
Why
Two runs of the same scheduled job can take the same row today. The maintenance task runner picks the oldest pending task without a lock (#552), and the GitLab webhook installer reads up to 100 rows without a lock, so two runs can each install a hook on the same project or group (#623).
This adds the columns for a per-run claim: a run locks its rows, stamps them with its
claim_run_idandclaimed_at, and makes every later write conditional on still holding that id.gitlab_webhookalso getsreinstall_requested_genandreinstall_done_gen, so a repair command can request a hook reinstall that an install already in progress cannot clear. Nothing reads the columns yet; the claim columns are nullable and both counters default to 0, so no existing row needs a reinstall.Summary
claim_run_idandclaimed_attomaintenance_tasksandgitlab_webhook, and the two reinstall counters togitlab_webhook.MaintenanceTaskandGitlabWebhookmodels gain the matching fields.Issue Number
Prepares the fixes for #552 and #623.
How to Test
tests/unit/test_migration_177_scheduled_job_claim_columns.pyupgrades and downgrades between 176 and 177, checks each column's type and default against the models, and checks that existing and new webhook rows need no reinstall.Video/Screenshots
N/A. No UI change.
Type
Notes
Adds migration 177. #691 and #692 build on this branch.
This PR was drafted by an AI agent on behalf of the user.
Enterprise server image for this PR: