Sha256: c74ac5e45dff5eecd128088ccdb28079152e9c7b13dc07247d7e0714ec4f5455

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true
# Provide service methods for getting a list of all authorities and scenarios for an authority.
module QaServer
  class JobIdCache
    class << self
      # Is the passed in job_id the active one for the job_key?
      # @param job_key [String] key unique to the job being run (e.g. "QaServer::Jobs::MonitorTestsJob")
      # @param job_id [String] UUID for job running the tests
      # @param expires_in [ActiveSupport::Duration]  This should be at least as long as the expected job run time to avoid multiple instances of the job running at the same time.
      # @note When job completes, call reset_job_id to invalidate the cache
      def active_job_id?(job_key:, job_id:, expires_in: 30.minutes)
        cached_job_id = Rails.cache.fetch(cache_key(job_key), expires_in: expires_in, race_condition_ttl: 5.minutes) { job_id }
        cached_job_id == job_id
      end

      # Delete cache for job id for the job represented by job_key.  Call this when the job completes.
      # @param job_key [String] key unique to the job being run (e.g. "QaServer::Jobs::MonitorTestsJob")
      def reset_job_id(job_key:)
        Rails.cache.delete(cache_key(job_key))
      end

    private

      def cache_key(job_key)
        "#{job_key}-job_id"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
qa_server-8.0.1 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.9.2 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.9.1 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.9.0 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.8.0 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.7.1 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.7.0 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.6.0 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.5.1 app/cache_processors/qa_server/job_id_cache.rb
qa_server-7.5.0 app/cache_processors/qa_server/job_id_cache.rb