Commit d2aa3e3d authored by Tomasz Maczukin's avatar Tomasz Maczukin

Merge branch 'introduce-job-keep-alive-api-endpoint' into 'master'

Make CI job update entrypoint to work as keep-alive endpoint

See merge request gitlab-org/gitlab-ce!19543
parents 1023a096 6139c013
---
title: Make CI job update entrypoint to work as keep-alive endpoint
merge_request: 19543
author:
type: changed
...@@ -59,6 +59,11 @@ module API ...@@ -59,6 +59,11 @@ module API
def max_artifacts_size def max_artifacts_size
Gitlab::CurrentSettings.max_artifacts_size.megabytes.to_i Gitlab::CurrentSettings.max_artifacts_size.megabytes.to_i
end end
def job_forbidden!(job, reason)
header 'Job-Status', job.status
forbidden!(reason)
end
end end
end end
end end
...@@ -125,7 +125,7 @@ module API ...@@ -125,7 +125,7 @@ module API
end end
put '/:id' do put '/:id' do
job = authenticate_job! job = authenticate_job!
forbidden!('Job is not running') unless job.running? job_forbidden!(job, 'Job is not running') unless job.running?
job.trace.set(params[:trace]) if params[:trace] job.trace.set(params[:trace]) if params[:trace]
...@@ -133,6 +133,8 @@ module API ...@@ -133,6 +133,8 @@ module API
project: job.project.full_path) project: job.project.full_path)
case params[:state].to_s case params[:state].to_s
when 'running'
job.touch if job.needs_touch?
when 'success' when 'success'
job.success! job.success!
when 'failed' when 'failed'
...@@ -152,7 +154,7 @@ module API ...@@ -152,7 +154,7 @@ module API
end end
patch '/:id/trace' do patch '/:id/trace' do
job = authenticate_job! job = authenticate_job!
forbidden!('Job is not running') unless job.running? job_forbidden!(job, 'Job is not running') unless job.running?
error!('400 Missing header Content-Range', 400) unless request.headers.key?('Content-Range') error!('400 Missing header Content-Range', 400) unless request.headers.key?('Content-Range')
content_range = request.headers['Content-Range'] content_range = request.headers['Content-Range']
......
...@@ -816,6 +816,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -816,6 +816,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect(job.reload.trace.raw).to eq 'BUILD TRACE' expect(job.reload.trace.raw).to eq 'BUILD TRACE'
end end
context 'when running state is sent' do
it 'updates update_at value' do
expect { update_job_after_time }.to change { job.reload.updated_at }
end
end
context 'when other state is sent' do
it "doesn't update update_at value" do
expect { update_job_after_time(20.minutes, state: 'success') }.not_to change { job.reload.updated_at }
end
end
end end
context 'when job has been erased' do context 'when job has been erased' do
...@@ -838,6 +850,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -838,6 +850,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED') update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(403)
expect(response.header['Job-Status']).to eq 'failed'
expect(job.trace.raw).to eq 'Job failed' expect(job.trace.raw).to eq 'Job failed'
expect(job).to be_failed expect(job).to be_failed
end end
...@@ -847,6 +860,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -847,6 +860,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
new_params = params.merge(token: token) new_params = params.merge(token: token)
put api("/jobs/#{job.id}"), new_params put api("/jobs/#{job.id}"), new_params
end end
def update_job_after_time(update_interval = 20.minutes, state = 'running')
Timecop.travel(job.updated_at + update_interval) do
update_job(job.token, state: state)
end
end
end end
describe 'PATCH /api/v4/jobs/:id/trace' do describe 'PATCH /api/v4/jobs/:id/trace' do
...@@ -979,6 +998,17 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -979,6 +998,17 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end end
end end
end end
context 'when the job is canceled' do
before do
job.cancel
patch_the_trace
end
it 'receives status in header' do
expect(response.header['Job-Status']).to eq 'canceled'
end
end
end end
context 'when Runner makes a force-patch' do context 'when Runner makes a force-patch' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment