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

20200930144340_set_job_waiter_ttl.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b15faa61deaad9adf98a46a92cf7d777da0a15de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class SetJobWaiterTtl < ActiveRecord::Migration[6.0]
  DOWNTIME = false

  SCRIPT = <<~LUA.freeze
    if redis.call("ttl", KEYS[1]) < 0 then
      redis.call("expire", KEYS[1], 21600)
    end
  LUA

  def up
    Gitlab::Redis::SharedState.with do |redis|
      cursor_init = '0'
      cursor = cursor_init

      loop do
        cursor, keys = redis.scan(cursor, match: 'gitlab:job_waiter:*')

        redis.pipelined do |redis|
          keys.each { |k| redis.eval(SCRIPT, keys: [k]) }
        end

        break if cursor == cursor_init
      end
    end
  end

  def down
  end
end