-
Notifications
You must be signed in to change notification settings - Fork 0
Scheduler fixes #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduler fixes #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -168,6 +168,8 @@ def format_local_time_filter(utc_dt, format_str='%Y-%m-%d %H:%M'): | |||||||||||||||||
|
|
||||||||||||||||||
| def schedule_all_repositories(): | ||||||||||||||||||
| """Schedule all active repositories on startup""" | ||||||||||||||||||
| from datetime import datetime # Import to ensure availability | ||||||||||||||||||
|
|
||||||||||||||||||
| try: | ||||||||||||||||||
| # Clean up any stuck 'running' jobs from previous sessions | ||||||||||||||||||
| stuck_jobs = BackupJob.query.filter_by(status='running').all() | ||||||||||||||||||
|
|
@@ -621,25 +623,32 @@ def favicon(): | |||||||||||||||||
| def schedule_backup_job(repository): | ||||||||||||||||||
| """Schedule a backup job for a repository""" | ||||||||||||||||||
| if not repository.is_active: | ||||||||||||||||||
| logger.info(f"Repository {repository.name} is inactive, not scheduling") | ||||||||||||||||||
| return | ||||||||||||||||||
|
|
||||||||||||||||||
| job_id = f'backup_{repository.id}' | ||||||||||||||||||
| logger.info(f"Attempting to schedule job {job_id} for repository {repository.name}") | ||||||||||||||||||
|
|
||||||||||||||||||
| # Remove existing job if it exists - try multiple ways to ensure it's gone | ||||||||||||||||||
| try: | ||||||||||||||||||
| if scheduler.get_job(job_id): | ||||||||||||||||||
| existing_job = scheduler.get_job(job_id) | ||||||||||||||||||
| if existing_job: | ||||||||||||||||||
| scheduler.remove_job(job_id) | ||||||||||||||||||
| logger.info(f"Removed existing scheduled job: {job_id}") | ||||||||||||||||||
| else: | ||||||||||||||||||
| logger.info(f"No existing job found for {job_id}") | ||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
| logger.warning(f"Could not remove existing job {job_id}: {e}") | ||||||||||||||||||
|
|
||||||||||||||||||
| # Double-check that job is really gone | ||||||||||||||||||
| if scheduler.get_job(job_id): | ||||||||||||||||||
| logger.error(f"Job {job_id} still exists after removal attempt") | ||||||||||||||||||
| logger.error(f"Job {job_id} still exists after removal attempt, aborting schedule") | ||||||||||||||||||
| return | ||||||||||||||||||
|
|
||||||||||||||||||
| # Create a wrapper function that includes Flask app context | ||||||||||||||||||
| def backup_with_context(): | ||||||||||||||||||
| from datetime import datetime, timedelta # Import inside function for closure scope | ||||||||||||||||||
|
|
||||||||||||||||||
| with app.app_context(): | ||||||||||||||||||
|
Comment on lines
649
to
652
|
||||||||||||||||||
| def backup_with_context(): | |
| from datetime import datetime, timedelta # Import inside function for closure scope | |
| with app.app_context(): | |
| def backup_with_context(): | |
| with app.app_context(): |
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using globals() for state management is an anti-pattern. Consider using a module-level variable instead, similar to how _scheduler_initialized is handled elsewhere in the code.
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using globals() for state management is an anti-pattern. Consider using a module-level variable instead, similar to how _scheduler_initialized is handled elsewhere in the code.
Copilot
AI
Sep 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using globals() for state management is an anti-pattern. Consider using a module-level variable instead, similar to how _scheduler_initialized is handled elsewhere in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant import -
datetimeis already imported at line 2. This duplicate import should be removed.