Ticket #27 (new enhancement)

Opened 5 months ago

Last modified 4 months ago

add cron style syntax on top of periodic timers in EM

Reported by: tmm1 Assigned to:
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc: raggi

Description

Here's a simple one I'm using to run something daily at a given time (i.e. EM.daily('9:00am'){ puts 'Wake up!!' })

require 'ramaze/snippets' # for 1.day
require 'time' # for Time.parse
require 'eventmachine'

module EventMachine
  def self.daily at, &blk
    time = Time.parse(at) - Time.now
    time += 1.day if time < 0

    EM.run do
      EM::add_timer(time) do
        blk.call
        EM::add_periodic_timer(1.day, &blk)
      end
    end
  end
end

Change History

07/20/08 05:15:38 changed by tmm1