Class: Borg::Worker

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::P::ObjectProtocol
Defined in:
lib/borg/borg_worker.rb

Constant Summary collapse

@@status_reports =
[]

Instance Method Summary collapse

Instance Method Details

#connection_completedObject



15
16
17
# File 'lib/borg/borg_worker.rb', line 15

def connection_completed
  send_object(WorkerConnected.new(self.signature))
end

#receive_object(ruby_object) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/borg/borg_worker.rb', line 6

def receive_object(ruby_object)
  case ruby_object
  when StartBuild
    update_code
  when StartTest
    start_test
  end
end

#redisObject



35
36
37
# File 'lib/borg/borg_worker.rb', line 35

def redis
  Redis.new(:host => Borg::Config.redis_ip,:port => Borg::Config.redis_port)
end

#send_final_report(last_status) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/borg/borg_worker.rb', line 62

def send_final_report(last_status)
  @@status_reports << last_status
  p @@status_reports
  error_flag = @@status_reports.any? {|x| x.exit_status != 0}
  
  if(error_flag)
    send_object(BuildStatus.new(1))
  else
    send_object(BuildStatus.new(0))
  end
  @@status_reports = []
end

#start_cucumber(last_status) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/borg/borg_worker.rb', line 50

def start_cucumber(last_status)
  @@status_reports << last_status
  if(redis.llen("cucumber") > 0)
    EM.popen("rake borg:cucumber RAILS_ENV=cucumber",TestRunner) do |process|
      process.worker = self
      process.runner_type = 'cucumber'
    end
  else
    send_final_report(BuildStatus.new(0))
  end
end

#start_testObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/borg/borg_worker.rb', line 39

def start_test
  if(redis.llen("tests") > 0)
    EM.popen("rake borg:test RAILS_ENV=test", TestRunner) do |process|
      process.worker = self
      process.runner_type = 'unit'
    end
  else
    start_cucumber(BuildStatus.new(0))
  end
end

#unbindObject



19
20
21
22
23
# File 'lib/borg/borg_worker.rb', line 19

def unbind
  EM.add_timer(3) {
    reconnect(Borg::Config.ip,Borg::Config.port)
  }
end

#update_codeObject



25
26
27
28
29
30
31
32
33
# File 'lib/borg/borg_worker.rb', line 25

def update_code
  source_control = Borg::Git.new()
  source_control.update()
  if(source_control.status)
    start_test
  else
    send_object(BuildStatus.new(1))
  end
end