Class: Debci::Experiment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/debci/experiment.rb

Instance Method Summary collapse

Instance Method Details

#packagesObject



15
16
17
# File 'lib/debci/experiment.rb', line 15

def packages
  @packages ||= Debci::Package.where(**self.package_selector)
end

#percent_completedObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/debci/experiment.rb', line 61

def percent_completed
  complete = 0
  total = 0
  Debci::Job.joins(
    'JOIN experiment_tests ON jobs.run_id in (experiment_tests.control_job_id, experiment_tests.test_job_id)'
  ).where(
    ['experiment_tests.experiment_id = ?', self.id]
  ).pluck(:status).each do |status|
    total += 1
    complete += 1 unless status.nil?
  end
  return 0 unless complete.positive?

  100 * complete.to_f / total.to_f
end

#startObject



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
48
49
50
51
52
53
54
55
# File 'lib/debci/experiment.rb', line 19

def start
  packages.in_batches do |batch|
    batch.each do |package|
      control_job = Debci::Job.create!(
        suite: suite,
        arch: arch,
        package: package,
        requestor: owner,
        priority: priority,
        **Hash(self.control_parameters)
      )
      test_job = Debci::Job.create!(
        suite: suite,
        arch: arch,
        package: package,
        requestor: owner,
        priority: priority,
        **Hash(self.test_parameters),
      )
      tests.create!(control_job: control_job, test_job: test_job)
      [control_job, test_job].each do |job|
        suite = job.suite
        arch = job.arch
        if package.reject_listed?(suite: suite, arch: arch)
          job.status = 'fail'
          job.date = Time.now
          job.save!
          pkg = package.name
          Debci.warn("#{pkg} (#{suite}/#{arch}) in the reject list, skipping")
          next
        end
        job.enqueue
      end
    end
  end
  update(started_at: Time.now)
end

#started?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/debci/experiment.rb', line 57

def started?
  !started_at.blank?
end