forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_observer.rb
More file actions
62 lines (51 loc) · 1.95 KB
/
process_observer.rb
File metadata and controls
62 lines (51 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
56
57
58
59
60
61
62
module VCAP::CloudController
module ProcessObserver
class << self
extend Forwardable
def configure(stagers, runners)
@stagers = stagers
@runners = runners
end
def deleted(process)
with_diego_communication_handling do
@runners.runner_for_process(process).stop
end
end
def updated(process)
changes = process.previous_changes
return unless changes
with_diego_communication_handling do
if changes.key?(:state) || changes.key?(:diego) || changes.key?(:enable_ssh) || changes.key?(:ports)
react_to_state_change(process)
elsif changes.key?(:instances)
react_to_instances_change(process)
end
end
end
private
def react_to_state_change(process)
unless process.started?
@runners.runner_for_process(process).stop
return
end
process.update(revision: process.app.latest_revision) if process.revisions_enabled?
# Reload to get the DB-assigned updated_at, which ProcessesSync compares against
# the LRP annotation to detect drift. Without this, the stale in-memory value
# causes an unnecessary re-sync.
@runners.runner_for_process(process.reload).start unless process.needs_staging?
end
def react_to_instances_change(process)
# Same as above: reload to get the DB-assigned updated_at before building the LRP annotation.
@runners.runner_for_process(process.reload).scale if process.started? && process.active?
end
def with_diego_communication_handling
yield
rescue Diego::Runner::CannotCommunicateWithDiegoError => e
logger.error("Failed communicating with diego backend: #{e.message}. Continuing, sync job should eventually re-sync any desired changes to diego.")
end
def logger
@logger ||= Steno.logger('cc.process_observer')
end
end
end
end