Class: Rearview::MonitorService
- Inherits:
-
Object
- Object
- Rearview::MonitorService
show all
- Includes:
- Celluloid, Logger
- Defined in:
- lib/rearview/monitor_service.rb
Defined Under Namespace
Classes: MonitorServiceError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
#logger
Constructor Details
Returns a new instance of MonitorService.
9
10
11
12
13
|
# File 'lib/rearview/monitor_service.rb', line 9
def initialize(jobs=[])
self.jobs = jobs
@supervisor = nil
@started = false
end
|
Instance Attribute Details
#jobs ⇒ Object
Returns the value of attribute jobs.
7
8
9
|
# File 'lib/rearview/monitor_service.rb', line 7
def jobs
@jobs
end
|
#supervisor ⇒ Object
Returns the value of attribute supervisor.
8
9
10
|
# File 'lib/rearview/monitor_service.rb', line 8
def supervisor
@supervisor
end
|
Instance Method Details
#add(job) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/rearview/monitor_service.rb', line 50
def add(job)
raise MonitorServiceError.new("service not started") unless started?
if @jobs[job.id]
logger.warn "#{self}#add job:#{job.id} already added"
else
@supervisor.add_tasks([job])
@jobs[job.id] = job
end
end
|
#remove(job) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/rearview/monitor_service.rb', line 59
def remove(job)
raise MonitorServiceError.new("service not started") unless started?
if !@jobs[job.id]
logger.warn "#{self}#remove job:#{job.id} has already been removed"
else
@supervisor.remove_tasks([job])
@jobs.delete(job.id)
end
end
|
#schedule(job) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/rearview/monitor_service.rb', line 35
def schedule(job)
logger.debug "#{self} schedule job: #{job.id}"
raise MonitorServiceError.new("service not started") unless started?
if @jobs[job.id]
remove(job)
end
add(job)
end
|
#shutdown ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/rearview/monitor_service.rb', line 28
def shutdown
logger.info "#{self} shutting down service..."
raise MonitorServiceError.new("service not started") unless started?
@supervisor.remove_all_tasks
@supervisor.terminate
@started = false
end
|
#started? ⇒ Boolean
17
18
19
|
# File 'lib/rearview/monitor_service.rb', line 17
def started?
@started
end
|
#startup ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/rearview/monitor_service.rb', line 20
def startup
logger.info "#{self} starting up service..."
raise MonitorServiceError.new("service already started") if started?
@supervisor = Rearview::MonitorSupervisor.run!
@supervisor.add_tasks(@jobs.values)
@started = true
end
|
#unschedule(job) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/rearview/monitor_service.rb', line 43
def unschedule(job)
logger.debug "#{self} unschedule job: #{job.id}"
raise MonitorServiceError.new("service not started") unless started?
if @jobs[job.id]
remove(job)
end
end
|