debian-mirror-gitlab/lib/gitlab/github_gists_import/status.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
942 B
Ruby
Raw Normal View History

2023-03-04 22:38:38 +05:30
# 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