Class: Juggler::JobRunner
- Inherits:
-
Object
- Object
- Juggler::JobRunner
show all
- Includes:
- StateMachine
- Defined in:
- lib/juggler/job_runner.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#bind, #change_state, included, #state
Constructor Details
#initialize(job, params, strategy) ⇒ JobRunner
Returns a new instance of JobRunner.
17
18
19
20
21
22
23
24
25
|
# File 'lib/juggler/job_runner.rb', line 17
def initialize(job, params, strategy)
@job = job
@params = params
@strategy = strategy
Juggler.logger.debug {
"#{to_s}: New job with body: #{params.inspect}"
}
@_state = :new
end
|
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
15
16
17
|
# File 'lib/juggler/job_runner.rb', line 15
def job
@job
end
|
Instance Method Details
#bury ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/juggler/job_runner.rb', line 57
def bury
Juggler.logger.warn { "#{to_s}: burying" }
release_def = job.bury(100000) release_def.callback {
change_state(:done)
}
release_def.errback {
change_state(:done)
}
end
|
#check_for_timeout ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/juggler/job_runner.rb', line 31
def check_for_timeout
if state == :running
if (time_left = @end_time - Time.now) < 1
Juggler.logger.info("#{to_s}: Timed out (#{time_left}s left)")
change_state(:timed_out)
end
end
end
|
#delete ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/juggler/job_runner.rb', line 68
def delete
dd = job.delete
dd.callback do
Juggler.logger.debug "#{to_s}: deleted"
change_state(:done)
end
dd.errback do
Juggler.logger.debug "#{to_s}: delete operation failed"
change_state(:done)
end
end
|
#release(delay = 0) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/juggler/job_runner.rb', line 44
def release(delay = 0)
Juggler.logger.debug { "#{to_s}: releasing" }
release_def = job.release(:delay => delay)
release_def.callback {
Juggler.logger.info { "#{to_s}: released for retry in #{delay}s" }
change_state(:done)
}
release_def.errback {
Juggler.logger.error { "#{to_s}: release failed (could not release)" }
change_state(:done)
}
end
|
#run ⇒ Object
27
28
29
|
# File 'lib/juggler/job_runner.rb', line 27
def run
change_state(:running)
end
|
#to_s ⇒ Object
40
41
42
|
# File 'lib/juggler/job_runner.rb', line 40
def to_s
"Job #{@job.jobid}"
end
|