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
def max_artifacts_size
Gitlab::CurrentSettings.max_artifacts_size.megabytes.to_i
end
def job_forbidden!(job, reason)
header 'Job-Status', job.status
forbidden!(reason)
end
end
end
end
......@@ -125,7 +125,7 @@ module API
end
put '/:id' do
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]
......@@ -133,6 +133,8 @@ module API
project: job.project.full_path)
case params[:state].to_s
when 'running'
job.touch if job.needs_touch?
when 'success'
job.success!
when 'failed'
......@@ -152,7 +154,7 @@ module API
end
patch '/:id/trace' do
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')
content_range = request.headers['Content-Range']
......
......@@ -816,6 +816,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect(job.reload.trace.raw).to eq 'BUILD TRACE'
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
context 'when job has been erased' do
......@@ -838,6 +850,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
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).to be_failed
end
......@@ -847,6 +860,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
new_params = params.merge(token: token)
put api("/jobs/#{job.id}"), new_params
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
describe 'PATCH /api/v4/jobs/:id/trace' do
......@@ -979,6 +998,17 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
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
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