diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/builds.rb | 2 | ||||
-rw-r--r-- | lib/api/helpers.rb | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/api/builds.rb b/lib/api/builds.rb index c4bcf88..e33491a 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -11,6 +11,7 @@ module API # POST /builds/register post "register" do authenticate_runner! + update_runner_last_contact required_attributes! [:token] build = RegisterBuildService.new.execute(current_runner) @@ -31,6 +32,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. # |