Upgrade to Pro — share decks privately, control downloads, hide ads and more …

clockwork

hkdnet
November 30, 2016

 clockwork

Shinjuku.rb #43 発表資料 https://shinjukurb.connpass.com/event/44524/

hkdnet

November 30, 2016
Tweet

More Decks by hkdnet

Other Decks in Programming

Transcript

  1. require 'clockwork' module Clockwork handler do |job| puts "Queueing job:

    #{job}" end every(10.seconds, 'run.me.every.10.seconds') every(1.hour, 'run.me.every.hour') every(1.day, 'custom.event.handler', :at => '00:30') do puts 'This event has its own handler' end # note: callbacks that return nil or false will cause event to not run on(:before_tick) do puts "tick" true end on(:after_tick) do puts "tock" true end end
  2. def execute @block.call(@job, @last) rescue => e @manager.log_error e @manager.handle_error

    e end def run(t) @last = t @block.call(@job) rescue => e log_error(e) end ৽ چ run͢ΔϒϩοΫʹ ݱࡏ࣌ࠁ͕౉ΔΑ͏ʹ
  3. def every(period, job, options={}, &block) event = Event.new(period, job, block

    || get_handler, options) @@events ||= [] @@events << event event end def every(period, job, options={}, &block) Clockwork.manager.every(period, job, options, &block) end Ϋϥεม਺͔Β ManagerΛ੾Γग़ͨ͠
  4. # note: callbacks that return nil or false will cause

    event to not run on(:before_tick) do puts "tick" true end ϑοΫ͕͍ͭͨ #### ֘౰Օॴͳ͠ ####
  5. %w[INT TERM HUP].each do |sig| trap sig do sig_write.puts(sig) end

    end trap('INT') do puts "\rExiting" exit end ରԠ͢Δγάφϧ͕ ૿͑ͨ
  6. require 'clockwork' module Clockwork handler do |job| puts "Queueing job:

    #{job}" end every(10.seconds, 'run.me.every') end require 'clockwork' include Clockwork handler do |job| puts "Running #{job}" end every(10.seconds, 'frequent.job') αϯϓϧͰ include͠ͳ͘ͳͬͨ