diff options
| author | Valery Sizov <vsv2711@gmail.com> | 2015-03-06 17:54:32 +0200 |
|---|---|---|
| committer | Valery Sizov <vsv2711@gmail.com> | 2015-03-06 17:54:32 +0200 |
| commit | 1c10220fa8bb519c97e6aea1af9620ac38c8a285 (patch) | |
| tree | a799a2fd40422c2a2af9ecc2a63655a2a826e619 /lib | |
| parent | 8452f94d44f8cc3ceb9b188e4a389a80e04f9eb4 (diff) | |
| parent | 3137c0e409ed44d3623bebbd71ced3909af55c63 (diff) | |
| download | gitlab-ci-1c10220fa8bb519c97e6aea1af9620ac38c8a285.tar.gz | |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ci
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/api/builds.rb | 4 | ||||
| -rw-r--r-- | lib/api/helpers.rb | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/api/builds.rb b/lib/api/builds.rb index c4bcf88..bed20ac 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -11,7 +11,10 @@ module API # POST /builds/register post "register" do authenticate_runner! + update_runner_last_contact required_attributes! [:token] + not_found! unless current_runner.active? + build = RegisterBuildService.new.execute(current_runner) if build @@ -31,6 +34,7 @@ module API # PUT /builds/:id put ":id" do authenticate_runner! + update_runner_last_contact build = Build.where(runner_id: current_runner.id).running.find(params[:id]) build.update_attributes(trace: params[:trace]) if params[:trace] diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index fc19d76..58297a8 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -2,6 +2,7 @@ module API module Helpers PRIVATE_TOKEN_PARAM = :private_token PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN" + UPDATE_RUNNER_EVERY = 60 def current_user @current_user ||= begin @@ -33,6 +34,12 @@ module API forbidden! unless project.valid_token?(params[:project_token]) end + def update_runner_last_contact + if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= UPDATE_RUNNER_EVERY + current_runner.update_attributes(contacted_at: Time.now) + end + end + # Checks the occurrences of required attributes, each attribute must be present in the params hash # or a Bad Request error is invoked. # |
