Module: Shipit::DeferredTouch

Extended by:
ActiveSupport::Concern
Included in:
CheckRun, Commit, MergeRequest, PullRequest, ReleaseStatus, Stack, Status, Task
Defined in:
app/models/concerns/shipit/deferred_touch.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SET_KEY =
'shipit:deferred_touches'
TMP_KEY =
"#{SET_KEY}:updating".freeze
CACHE_KEY =
"#{SET_KEY}:scheduled".freeze
THROTTLE_TTL =
1.second

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



18
19
20
# File 'app/models/concerns/shipit/deferred_touch.rb', line 18

def enabled
  @enabled
end

Class Method Details

.touch_now!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/concerns/shipit/deferred_touch.rb', line 20

def touch_now!
  now = Time.now.utc
  fetch do |touches|
    records = []
    touches.each do |model, changes|
      changes.each do |attribute, ids|
        records << [model.where(id: ids).to_a, attribute]
      end
    end

    ActiveRecord::Base.transaction do
      records.each do |instances, attribute|
        instances.each { |i| i.touch(attribute, time: now) }
      end
    end
  end
end