Class: QaServer::JobIdCache

Inherits:
Object
  • Object
show all
Defined in:
app/cache_processors/qa_server/job_id_cache.rb

Class Method Summary collapse

Class Method Details

.active_job_id?(job_key:, job_id:, expires_in: 30.minutes) ⇒ Boolean

Note:

When job completes, call reset_job_id to invalidate the cache

Is the passed in job_id the active one for the job_key?

Parameters:

  • job_key (String)

    key unique to the job being run (e.g. “QaServer::Jobs::MonitorTestsJob”)

  • job_id (String)

    UUID for job running the tests

  • expires_in (ActiveSupport::Duration) (defaults to: 30.minutes)

    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.

Returns:

  • (Boolean)


11
12
13
14
# File 'app/cache_processors/qa_server/job_id_cache.rb', line 11

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

.reset_job_id(job_key:) ⇒ Object

Delete cache for job id for the job represented by job_key. Call this when the job completes.

Parameters:

  • job_key (String)

    key unique to the job being run (e.g. “QaServer::Jobs::MonitorTestsJob”)



18
19
20
# File 'app/cache_processors/qa_server/job_id_cache.rb', line 18

def reset_job_id(job_key:)
  Rails.cache.delete(cache_key(job_key))
end