Class: Debci::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/collector.rb

Defined Under Namespace

Classes: CLI

Instance Method Summary collapse

Instance Method Details

#receive(directory) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/debci/collector.rb', line 51

def receive(directory)
  job = Debci::Job.receive(directory)

  if job.nil?
    Debci.log("receiving from #{directory} failed associating a job")
  else
    data = {
      package: job.package.name,
      suite: job.suite,
      arch: job.arch,
      backend: job.backend,
      status: job.status,
      duration_human: job.duration_human,
      run_id: job.run_id,
    }
    Debci.log('%<package>s %<suite>s/%<arch>s/%<backend>s (%<run_id>s) %<status>s %<duration_human>s' % data)
  end
end

#receive_payload(dir, payload) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/debci/collector.rb', line 28

def receive_payload(dir, payload)
  return if payload.nil? || payload.empty?
  return unless File.directory?(dir)

  Dir.chdir(dir) do
    results = Pathname('results.tar.gz')
    results.open('wb') do |f|
      f.write(payload)
    end
    begin
      Debci.run('tar', 'xaf', results.to_s)
    rescue Debci::CommandFailed
      Debci.warn("W: received invalid tarball data")
    end
    results.unlink
  end

  exitcodes = Pathname(dir).glob('**/exitcode')
  return if exitcodes.empty?

  receive(exitcodes.first.parent)
end

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/debci/collector.rb', line 11

def run
  Debci.log "debci collector started"
  channel = Debci::AMQP.amqp_channel
  queue = Debci::AMQP.results_queue
  queue.subscribe(manual_ack: true) do |delivery_info, _properties, payload|
    Dir.mktmpdir do |dir|
      receive_payload(dir, payload)
    end
    channel.acknowledge(delivery_info.delivery_tag, false)
  end
  begin
    loop { sleep 1 }
  rescue Interrupt
    Debci.log "debci collector stopped"
  end
end