Module: Scheduler::Deferrable
- Included in:
- Defer
- Defined in:
- lib/scheduler/defer.rb
Instance Method Summary collapse
-
#async=(val) ⇒ Object
for test.
- #do_all_work ⇒ Object
- #initialize ⇒ Object
- #later(desc = nil, db = Scheduler.configuration.current_db, &blk) ⇒ Object
- #pause ⇒ Object
- #resume ⇒ Object
- #stop! ⇒ Object
-
#stopped? ⇒ Boolean
test only.
Instance Method Details
#async=(val) ⇒ Object
for test
21 22 23 |
# File 'lib/scheduler/defer.rb', line 21 def async=(val) @async = val end |
#do_all_work ⇒ Object
44 45 46 47 48 |
# File 'lib/scheduler/defer.rb', line 44 def do_all_work while !@queue.empty? do_work(_non_block=true) end end |
#initialize ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/scheduler/defer.rb', line 3 def initialize @async = !Rails.env.test? @queue = Queue.new @mutex = Mutex.new @paused = false @thread = nil end |
#later(desc = nil, db = Scheduler.configuration.current_db, &blk) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/scheduler/defer.rb', line 25 def later(desc = nil, db=Scheduler.configuration.current_db, &blk) if @async start_thread unless (@thread && @thread.alive?) || @paused @queue << [db, blk, desc] else blk.call end end |
#pause ⇒ Object
11 12 13 14 |
# File 'lib/scheduler/defer.rb', line 11 def pause stop! @paused = true end |
#resume ⇒ Object
16 17 18 |
# File 'lib/scheduler/defer.rb', line 16 def resume @paused = false end |
#stop! ⇒ Object
34 35 36 37 |
# File 'lib/scheduler/defer.rb', line 34 def stop! @thread.kill if @thread && @thread.alive? @thread = nil end |
#stopped? ⇒ Boolean
test only
40 41 42 |
# File 'lib/scheduler/defer.rb', line 40 def stopped? !(@thread && @thread.alive?) end |