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

worker_state.rb « phabricator_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ffa2d3d7a4379218b9e4fe8c7b0d2038d16f666c (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
44
45
46
47
# frozen_string_literal: true
module Gitlab
  module PhabricatorImport
    class WorkerState
      def initialize(project_id)
        @project_id = project_id
      end

      def add_job
        redis.with do |r|
          r.pipelined do |pipe|
            pipe.incr(all_jobs_key)
            pipe.expire(all_jobs_key, timeout)
          end
        end
      end

      def remove_job
        redis.with do |r|
          r.decr(all_jobs_key)
        end
      end

      def running_count
        redis.with { |r| r.get(all_jobs_key) }.to_i
      end

      private

      attr_reader :project_id

      def redis
        Gitlab::Redis::SharedState
      end

      def all_jobs_key
        @all_jobs_key ||= "phabricator-import/jobs/project-#{project_id}/job-count"
      end

      def timeout
        # Make sure we get rid of all the information after a job is marked
        # as failed/succeeded
        Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION
      end
    end
  end
end