Class: AmplitudeExperiment::CohortLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/experiment/cohort/cohort_loader.rb

Overview

CohortLoader

Instance Method Summary collapse

Constructor Details

#initialize(cohort_download_api, cohort_storage) ⇒ CohortLoader

Returns a new instance of CohortLoader.



4
5
6
7
8
9
# File 'lib/experiment/cohort/cohort_loader.rb', line 4

def initialize(cohort_download_api, cohort_storage)
  @cohort_download_api = cohort_download_api
  @cohort_storage = cohort_storage
  @jobs = {}
  @lock_jobs = Mutex.new
end

Instance Method Details

#load_cohort(cohort_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/experiment/cohort/cohort_loader.rb', line 11

def load_cohort(cohort_id)
  @lock_jobs.synchronize do
    unless @jobs.key?(cohort_id)
      future = Concurrent::Promises.future do
        load_cohort_internal(cohort_id)
      ensure
        remove_job(cohort_id)
      end
      @jobs[cohort_id] = future
    end
    @jobs[cohort_id]
  end
end