summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ci/api/builds.rb17
-rw-r--r--lib/ci/api/helpers.rb3
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb
index ed87a2603e8..1ec4584a13f 100644
--- a/lib/ci/api/builds.rb
+++ b/lib/ci/api/builds.rb
@@ -16,6 +16,15 @@ module Ci
not_found! unless current_runner.active?
update_runner_info
+ last_update = Gitlab::Redis.with { |redis| redis.get(current_runner_redis_key)}
+
+ if params[:last_update] != ""
+ if :last_update == last_update
+ headers 'X-GitLab-Last-Update', last_update
+ return build_not_found!
+ end
+ end
+
build = Ci::RegisterBuildService.new.execute(current_runner)
if build
@@ -26,6 +35,14 @@ module Ci
else
Gitlab::Metrics.add_event(:build_not_found)
+ if last_update == ""
+ Gitlab::Redis.with do |redis]
+ new_update = Time.new.inspect
+ redis.set(current_runner_redis_key, new_update, ex: 60.minutes)
+ headers 'X-GitLab-Last-Update', new_update
+ end
+ end
+
build_not_found!
end
end
diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb
index e608f5f6cad..ef80e0df5d3 100644
--- a/lib/ci/api/helpers.rb
+++ b/lib/ci/api/helpers.rb
@@ -60,6 +60,9 @@ module Ci
@runner ||= Runner.find_by_token(params[:token].to_s)
end
+ def current_runner_redis_key
+ @runner_redis_key ||= "#{current_runner.token}_#{current_runner.tag_list}"
+
def get_runner_version_from_params
return unless params["info"].present?
attributes_for_keys(["name", "version", "revision", "platform", "architecture"], params["info"])