Module: RRRSpec::Server::StatisticsUpdater

Defined in:
lib/rrrspec/server/statistics_updater.rb

Constant Summary collapse

ESTIMATION_FIELDS =
[
  "`spec_file`",
  "avg(UNIX_TIMESTAMP(`trials`.`finished_at`)-UNIX_TIMESTAMP(`trials`.`started_at`)) as `avg`",
  # "avg(`trials`.`finished_at`-`trials`.`started_at`) as `avg`",
]

Class Method Summary collapse

Class Method Details

.recalculate_estimate_sec(taskset) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rrrspec/server/statistics_updater.rb', line 38

def recalculate_estimate_sec(taskset)
  RRRSpec.logger.debug("Calculating estimate sec for taskset #{taskset.key}")

  start = Time.now 

  p_obj = Persistence::Taskset.where(key: taskset.key).first
  taskset_class = p_obj.taskset_class
  query = Persistence::Task.joins(:trials).joins(:taskset).
    select(ESTIMATION_FIELDS).
    where('tasksets.taskset_class' => taskset_class).
    where('trials.status' => ["passed", "pending"]).
    group('spec_file')
  estimation = {}
  query.each do |row|
    estimation[row.spec_file] = row.avg.to_i
  end
  unless estimation.empty?
    TasksetEstimation.update_estimate_secs(taskset_class, estimation)
  end

  RRRSpec.logger.info("Recalculated estimate sec for taskset #{taskset.key} (total: #{Time.now - start} seconds)")
end

.update_estimate_sec(taskset) ⇒ Object



35
36
# File 'lib/rrrspec/server/statistics_updater.rb', line 35

def update_estimate_sec(taskset)
end

.workObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rrrspec/server/statistics_updater.rb', line 16

def work
  taskset, recalculate = StatisticsUpdaterQueue.dequeue
  recalculate = true

  ActiveRecord::Base.connection_pool.with_connection do
    unless Persistence::Taskset.where(key: taskset.key).exists?
      RRRSpec.logger.warn("StatisticsUpdater: Ignoreing unpersisted taskset: #{taskset.key}")
    end

    if recalculate
      recalculate_estimate_sec taskset
    else
      update_estimate_sec taskset
    end
  end
rescue
  RRRSpec.logger.error($!)
end

.work_loopObject



12
13
14
# File 'lib/rrrspec/server/statistics_updater.rb', line 12

def work_loop
  loop { work }
end