Skip to content

Fix DPSJob.wait_for_completion() race condition with initial delay#127

Merged
sujen1412 merged 1 commit into
developfrom
claude/dps-job-polling-docs-hgE05
Apr 30, 2026
Merged

Fix DPSJob.wait_for_completion() race condition with initial delay#127
sujen1412 merged 1 commit into
developfrom
claude/dps-job-polling-docs-hgE05

Conversation

@sujen1412
Copy link
Copy Markdown
Contributor

Summary

Fixes the race condition in DPSJob.wait_for_completion() where the method would return immediately with an incorrect "Deleted" status if called right after job submission, before the job appears in the OpenSearch database.

Problem

  • When jobs are submitted via DPS API, they take up to 5 seconds to appear in the OpenSearch database
  • If wait_for_completion() is called immediately after submission, the API returns an unexpected status before the job appears in the database
  • The method would return immediately with this incorrect status instead of retrying

Solution

Implemented an initial delay mechanism:

  • Added initial_delay_seconds parameter (default 5 seconds) to wait_for_completion()
  • The method now waits 5 seconds before the first status check, allowing the job to appear in the database
  • Improved status check logic to properly handle all non-terminal states by retrying

Changes

  • ✅ Added time module import
  • ✅ Added initial_delay_seconds parameter with default value of 5 seconds
  • ✅ Added initial sleep before first status check
  • ✅ Changed status check logic from whitelist (accepted/running) to blacklist (terminal states)
  • ✅ Updated docstring with parameter documentation

Testing

Users can now reliably call wait_for_completion() immediately after job submission:

job = maap.submit_job(...)
job.wait_for_completion()  # Waits 5 seconds then polls correctly
print(f"Status: {job.status}")  # Returns "Succeeded" (or other terminal state)

To disable the initial delay for existing jobs (where status is already available):

job.wait_for_completion(initial_delay_seconds=0)

Related Issues

Fixes #126

https://claude.ai/code/session_01KEDGhwSuoY9N5inWR9bk5u


Generated by Claude Code

Add a default 5-second initial delay before the first status check to allow
newly submitted jobs to appear in the OpenSearch database. This fixes the issue
where wait_for_completion() would return immediately with incorrect status
('Deleted') if called right after job submission.

Changes:
- Add time module import
- Add initial_delay_seconds parameter (default 5) to wait_for_completion()
- Improve status check logic to handle any non-terminal state by retrying
- Update docstring with parameter documentation

Fixes issue #126

https://claude.ai/code/session_01KEDGhwSuoY9N5inWR9bk5u
@sujen1412 sujen1412 merged commit 7eaecd3 into develop Apr 30, 2026
3 checks passed
@sujen1412 sujen1412 deleted the claude/dps-job-polling-docs-hgE05 branch April 30, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants