Commit 435e661a authored by Tomasz Maczukin's avatar Tomasz Maczukin

Introduce new keep-alive API entrypoint for CI job

parent df326d06
...@@ -140,6 +140,22 @@ module API ...@@ -140,6 +140,22 @@ module API
end end
end end
desc 'Marks job as live' do
http_codes [[200, 'Request accepted']]
end
params do
requires :id, type: Integer, desc: %q(Job's ID)
optional :token, type: String, desc: %q(Job's authentication token)
end
post '/:id/keep-alive' do
job = authenticate_job!
job.touch if job.running? && job.needs_touch?
status 200
header 'Job-Status', job.status
end
desc 'Appends a patch to the job trace' do desc 'Appends a patch to the job trace' do
http_codes [[202, 'Trace was patched'], http_codes [[202, 'Trace was patched'],
[400, 'Missing Content-Range header'], [400, 'Missing Content-Range header'],
......
...@@ -849,6 +849,68 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -849,6 +849,68 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end end
end end
describe 'POST /api/v4/jobs/:id/keep-alive' do
let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) }
let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } }
let(:update_interval) { 30.seconds }
it 'returns correct response' do
keep_alive_job
expect(response.status).to eq 200
expect(response.header).to have_key 'Job-Status'
end
it 'updates updated_at value' do
expect { keep_alive_job }.to change { job.updated_at }
end
context 'when project for the build has been deleted' do
let(:job) do
create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) do |job|
job.project.update(pending_delete: true)
end
end
it 'responds with forbidden' do
keep_alive_job
expect(response.status).to eq(403)
end
end
context 'when job has been canceled' do
before do
job.cancel
end
it 'returns job-status=canceled header' do
keep_alive_job
expect(response.status).to eq 200
expect(response.header['Job-Status']).to eq('canceled')
end
end
context 'when job has been errased' do
let(:job) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) }
it 'rresponds with forbidden' do
keep_alive_job
expect(response.status).to eq 403
end
end
def keep_alive_job(token = job.token, **params)
new_params = params.merge(token: token)
Timecop.travel(job.updated_at + update_interval) do
post api("/jobs/#{job.id}/keep-alive"), new_params
job.reload
end
end
end
describe 'PATCH /api/v4/jobs/:id/trace' do describe 'PATCH /api/v4/jobs/:id/trace' do
let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) } let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) }
let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } } let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } }
......
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