Skip to content

Implement automatic date tracking for job start and finish times#24

Merged
nolan1999 merged 5 commits intomainfrom
copilot/fix-14
Aug 6, 2025
Merged

Implement automatic date tracking for job start and finish times#24
nolan1999 merged 5 commits intomainfrom
copilot/fix-14

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 4, 2025

The jobs table contains date_started and date_finished columns that were never being updated. This PR implements automatic tracking of these timestamps during job lifecycle events.

Changes Made

Enhanced Job Status Updates (api/endpoints/job_update.py):

  • Added logic to set date_started when job status changes to "pulled" (first time only)
  • Added logic to set date_finished when job reaches terminal states ("finished" or "error") (first time only)
  • Dates are only set if currently None to prevent overwriting

Comprehensive Test Coverage:

  • Added tests verifying dates are set on appropriate status transitions
  • Added tests ensuring dates are not overwritten once set
  • Added tests confirming both terminal states trigger date_finished
  • Added tests verifying non-triggering statuses don't affect dates

Job Lifecycle Timeline

queued → pulled → preprocessing → running → postprocessing → finished
  ↑        ↑                                                      ↑
created  started                                              finished

Benefits

  • Performance Tracking: Enables measurement of job execution times
  • Resource Planning: Helps understand job duration patterns
  • SLA Monitoring: Supports tracking against service level agreements
  • Analytics: Enables historical analysis of job performance
  • Backward Compatible: Existing jobs continue to work unchanged

Example Usage

# After job is pulled by worker
update_job_status(JobUpdate(job_id=42, status=JobStates.pulled))
# → job.date_started is now set

# After job completes successfully  
update_job_status(JobUpdate(job_id=42, status=JobStates.finished))
# → job.date_finished is now set

# Calculate execution time
execution_time = job.date_finished - job.date_started

The implementation uses minimal, surgical changes focused only on the job status update endpoint while maintaining full backward compatibility.

Fixes #14.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nolan1999 <54246789+nolan1999@users.noreply.github.com>
Copilot AI changed the title [WIP] Update date started, date finished on status updates Implement automatic date tracking for job start and finish times Aug 4, 2025
Copilot AI requested a review from nolan1999 August 4, 2025 21:40
Comment thread api/models.py Outdated
user_email = mapped_column(String, nullable=True) # required for notifications
job_name = mapped_column(String)
date_created = mapped_column(DateTime, default=datetime.datetime.utcnow)
date_created = mapped_column(DateTime, default=lambda: datetime.datetime.now(datetime.timezone.utc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the current version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the date_created field to use the original datetime.utcnow as requested in commit 5a937fd.

Co-authored-by: nolan1999 <54246789+nolan1999@users.noreply.github.com>
Copilot AI requested a review from nolan1999 August 4, 2025 21:54
@nolan1999 nolan1999 force-pushed the copilot/fix-14 branch 2 times, most recently from 1490620 to e538ac9 Compare August 4, 2025 22:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 4, 2025

Coverage

Coverage Report
FileStmtsMissCoverMissing
api
   __init__.py00100% 
   database.py13469%22–26
   dependencies.py512159%32–37, 59, 69, 78–97, 103–115
   exceptions.py9278%10, 18
   main.py24388%35, 45, 50
   models.py430100% 
   settings.py772370%15–18, 28–29, 65–69, 74, 78, 86, 95–101, 104–109, 112, 121
   tags.py10100% 
api/core
   __init__.py00100% 
   aws.py5180%7
   filesystem.py2253385%35, 48, 51, 54, 59, 66, 72, 87, 90, 93, 96, 99, 109, 114, 194, 196–205, 219, 291, 348, 356–368, 379, 410
   notifications.py271352%14, 28–29, 32–52
api/crud
   __init__.py00100% 
   job.py71494%30, 56, 144–145
api/endpoints
   __init__.py00100% 
   auth.py654925%30–69, 79–106, 118–155
   auth_get.py14286%22, 39
   files.py52688%26–27, 42–43, 112, 128
   job_update.py29293%28, 45
   jobs.py34294%24, 88
api/schemas
   __init__.py00100% 
   file.py240100% 
   job.py116992%27, 33, 36, 42, 47, 76, 85, 91, 93
   job_update.py60100% 
   token.py40100% 
   user.py140100% 
TOTAL90417481% 

Tests Skipped Failures Errors Time
128 0 💤 0 ❌ 0 🔥 11m 55s ⏱️

@nolan1999 nolan1999 marked this pull request as ready for review August 6, 2025 21:07
@nolan1999 nolan1999 merged commit 5b9f5ff into main Aug 6, 2025
3 of 4 checks passed
@nolan1999 nolan1999 deleted the copilot/fix-14 branch August 6, 2025 21:07
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.

Update date started, date finished on status updates

2 participants