File: example.rb

package info (click to toggle)
ruby-clockwork 2.0.3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 332 kB
  • sloc: ruby: 1,583; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'clockwork'

module Clockwork
  handler do |job|
    puts "Queueing job: #{job}"
  end

  every(10.seconds, 'run.me.every.10.seconds')
  every(1.minute, 'run.me.every.minute')
  every(1.hour, 'run.me.every.hour')

  every(1.day, 'run.me.at.midnight', :at => '00:00')

  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