Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-15 20:08:29 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 19:45:45 +0300
commit3d26a8d0b62f70e02917f7601bc2032fb3aed7e6 (patch)
treeb982f0762e2b495d05a1253b12c11806dd2cee44 /lib/api/runner.rb
parentb8ca9bc43a9504dad94a66630170ab6311eb5c09 (diff)
Add jobs requesting API
Diffstat (limited to 'lib/api/runner.rb')
-rw-r--r--lib/api/runner.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index 47858f1866b..2e7b96e5169 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -48,5 +48,44 @@ module API
Ci::Runner.find_by_token(params[:token]).destroy
end
end
+
+ resource :jobs do
+ desc 'Request a job' do
+ success Entities::RequestJobResponse
+ end
+ params do
+ requires :token, type: String, desc: %q(Runner's authentication token)
+ end
+ post '/request' do
+ authenticate_runner!
+ not_found! unless current_runner.active?
+ update_runner_info
+
+ if current_runner.is_runner_queue_value_latest?(params[:last_update])
+ header 'X-GitLab-Last-Update', params[:last_update]
+ Gitlab::Metrics.add_event(:build_not_found_cached)
+ return build_not_found!
+ end
+
+ new_update = current_runner.ensure_runner_queue_value
+ result = ::Ci::RegisterBuildService.new(current_runner).execute
+
+ if result.valid?
+ if result.build
+ Gitlab::Metrics.add_event(:build_found,
+ project: result.build.project.path_with_namespace)
+ present result.build, with: Entities::RequestJobResponse
+ else
+ Gitlab::Metrics.add_event(:build_not_found)
+ header 'X-GitLab-Last-Update', new_update
+ build_not_found!
+ end
+ else
+ # We received build that is invalid due to concurrency conflict
+ Gitlab::Metrics.add_event(:build_invalid)
+ conflict!
+ end
+ end
+ end
end
end