blob: e997eb0bf885ebd5dadcb48c6008bb0373a9c737 (
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
32
33
34
35
36
37
38
39
40
41
42
43
|
# frozen_string_literal: true
module Gitlab
module GithubGistsImport
class Status
IMPORT_STATUS_KEY = 'gitlab:github-gists-import:%{user_id}'
EXPIRATION_TIME = 24.hours
def initialize(user_id)
@user_id = user_id
end
def start!
change_status('started')
end
def fail!
change_status('failed')
end
def finish!
change_status('finished')
end
def started?
Gitlab::Redis::SharedState.with { |redis| redis.get(import_status_key) == 'started' }
end
private
def change_status(status_name)
Gitlab::Redis::SharedState.with do |redis|
redis.set(import_status_key, status_name)
redis.expire(import_status_key, EXPIRATION_TIME) unless status_name == 'started'
end
end
def import_status_key
format(IMPORT_STATUS_KEY, user_id: @user_id)
end
end
end
end
|