Skip to content

Commit 36f73e2

Browse files
committed
Change from GoodJob::Execution to GoodJob::Job for upload tracking.
Only one Job is created per job, but an upload which is failed or retried could result in more than one execution.
1 parent 9353ed4 commit 36f73e2

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

app/controllers/api/school_import_jobs_controller.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ def show
1919
private
2020

2121
def find_job
22-
# GoodJob stores jobs in the good_jobs table as Executions
23-
# The job_id returned to users is the ActiveJob ID
24-
# We need to query by active_job_id, not by execution id
25-
job = GoodJob::Execution.find_by(active_job_id: params[:id])
22+
job = GoodJob::Job.find_by(active_job_id: params[:id])
2623

2724
# Verify this is an import job (security check)
2825
return nil unless job && job.job_class == SchoolImportJob.name
@@ -40,7 +37,7 @@ def build_job_response(job)
4037
}
4138

4239
# If job is finished successfully, get results from dedicated table
43-
if job.finished_at.present? && job.error.blank?
40+
if job.succeeded?
4441
result = SchoolImportResult.find_by(job_id: job.active_job_id)
4542
if result
4643
response[:results] = result.results
@@ -49,20 +46,21 @@ def build_job_response(job)
4946
end
5047
end
5148

52-
# Include error if job failed
49+
# Include error if job failed or was discarded
5350
if job.error.present?
5451
response[:error] = job.error
55-
response[:status] = 'failed'
52+
response[:status] = job.discarded? ? 'discarded' : 'failed'
5653
end
5754

5855
response
5956
end
6057

6158
def job_status(job)
62-
return 'failed' if job.error.present?
63-
return 'completed' if job.finished_at.present?
59+
return 'discarded' if job.discarded?
60+
return 'succeeded' if job.succeeded?
61+
return 'failed' if job.finished? && job.error.present?
62+
return 'running' if job.running?
6463
return 'scheduled' if job.scheduled_at.present? && job.scheduled_at > Time.current
65-
return 'running' if job.performed_at.present? && job.finished_at.nil?
6664

6765
'queued'
6866
end

app/fields/status_field.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ def to_s
1010
def job_status
1111
return 'unknown' if data.blank?
1212

13-
job = GoodJob::Execution.find_by(active_job_id: data)
13+
job = GoodJob::Job.find_by(active_job_id: data)
1414
return 'not_found' unless job
1515

16-
return 'failed' if job.error.present?
17-
return 'completed' if job.finished_at.present?
16+
return 'discarded' if job.discarded?
17+
return 'succeeded' if job.succeeded?
18+
return 'failed' if job.finished? && job.error.present?
19+
return 'running' if job.running?
1820
return 'scheduled' if job.scheduled_at.present? && job.scheduled_at > Time.current
19-
return 'running' if job.performed_at.present? && job.finished_at.nil?
2021

2122
'queued'
2223
end
2324

2425
def status_class
2526
case job_status
27+
when 'succeeded' then 'status-completed'
2628
when 'completed' then 'status-completed'
2729
when 'failed' then 'status-failed'
30+
when 'discarded' then 'status-failed'
2831
when 'running' then 'status-running'
2932
when 'queued', 'scheduled' then 'status-queued'
3033
else 'status-unknown'

spec/features/school/importing_schools_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
context 'when job exists and is completed' do
8383
before do
84-
GoodJob::Execution.create!(
84+
GoodJob::Job.create!(
8585
id: SecureRandom.uuid,
8686
active_job_id: job_id,
8787
queue_name: 'import_schools_job',
@@ -107,7 +107,7 @@
107107
expect(response).to have_http_status(:ok)
108108
data = JSON.parse(response.body, symbolize_names: true)
109109

110-
expect(data[:status]).to eq('completed')
110+
expect(data[:status]).to eq('succeeded')
111111
expect(data[:results][:successful].count).to eq(1)
112112
end
113113
end

0 commit comments

Comments
 (0)