Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
435e661a
Commit
435e661a
authored
Jun 07, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce new keep-alive API entrypoint for CI job
parent
df326d06
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
lib/api/runner.rb
lib/api/runner.rb
+16
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+62
-0
No files found.
lib/api/runner.rb
View file @
435e661a
...
...
@@ -140,6 +140,22 @@ module API
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
http_codes
[[
202
,
'Trace was patched'
],
[
400
,
'Missing Content-Range header'
],
...
...
spec/requests/api/runner_spec.rb
View file @
435e661a
...
...
@@ -849,6 +849,68 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
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
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'
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment