Skip to content

Commit

Permalink
Fix bug with cursor state naemspace
Browse files Browse the repository at this point in the history
  • Loading branch information
isra17 committed May 6, 2024
1 parent d4b7727 commit 377178a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions example/definitions/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ spec:
config:
job_state:
cursors_states_enabled: true
cursors_states_namespace: example-namespace
job:
buffer_size: 5

13 changes: 10 additions & 3 deletions src/saturn_engine/stores/jobs_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from datetime import datetime

import sqlalchemy as sa
from sqlalchemy import select
from sqlalchemy import union_all
from sqlalchemy import update
Expand Down Expand Up @@ -190,13 +191,19 @@ def fetch_cursors_states(
fetch_stmts = []
for job, cursors in query.items():
fetch_stmts.append(
select(Job.name, JobCursorState)
select(JobCursorState, sa.func.coalesce(Job.name, job).label("name"))
.join(
JobCursorState,
Job,
Job.job_definition_name == JobCursorState.job_definition_name,
isouter=True,
)
.where(
Job.name == job,
sa.or_(
Job.name == job,
sa.and_(
Job.name.is_(None), JobCursorState.job_definition_name == job
),
),
JobCursorState.cursor.in_(cursors),
)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/worker_manager/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def test_sync_states(
},
},
orphan_job.name: {"cursors_states": {"a": {"x": 1}}},
}
},
}
},
)
Expand Down

0 comments on commit 377178a

Please sign in to comment.