Skip to content

job.scheduled_at cannot be assumed and crashes job.duration #282

@freesteph

Description

@freesteph

In a recent commit, job.duration has been introduced, which computes the job's duration by substracting scheduled_at from finished_at. However, scheduled_at isn't always set because jobs can simply be enqueued with perform_later and Rails will not always set it (that's my guess from our production systems).

This prevents the show page for jobs to load for us:

Completed 500 Internal Server Error in 15ms (ActiveRecord: 3.6ms (6 queries, 0 cached) | GC: 0.0ms)                                                       
    59:       </td>                                                                                                                                       
ActionView::Template::Error (can't convert NilClass into an exact number)                                                                                 
Caused by: TypeError (can't convert NilClass into an exact number)                                                                                        
    58:         <%= job.duration.round(3) %> seconds                                                                                                      
Started GET "/jobs/applications/<redacted>/jobs/<redacted>

A possible fix would be to fetch created_at if scheduled_at hasn't been set?

https://github.com/rails/mission_control-jobs/blob/1cfb47fd3b045fdcd9d33685274ae7fddd56ec4d/lib/active_job/job_proxy.rb#L27C1-L29C6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions