Module: MongoJob::Mixins::FiberRunner::InstanceMethods
Instance Method Summary collapse
Instance Method Details
#run_defined_tasks ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mongojob/mixins/fiber_runner.rb', line 36 def run_defined_tasks tasks = nil self.class.class_eval do tasks = @tasks || [] end tasks.each do |task| run_em_fiber task[:period] do self.send task[:method_name], *task[:args] end end end |
#run_em_fiber(period, &blk) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongojob/mixins/fiber_runner.rb', line 14 def run_em_fiber period, &blk # log.info "Starting tick #{method_name} with period #{period} seconds" Fiber.new do loop do f = Fiber.current begin # log.debug "Running method #{method_name}" blk.call rescue Exception => e # do something # log.error "Caught exception when running #{method_name}" # log.error e p e end EM.add_timer period do f.resume end Fiber.yield end end.resume end |