diff --git a/README.md b/README.md index f5432dc..892eb32 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,9 @@ Event Parameters **:MM HH:** (Mon|mon|Monday|monday) HH:MM + (Mon|mon|Monday|monday) HH:** + (Mon|mon|Monday|monday) **:MM + (Mon|mon|Monday|monday) **:** #### Examples @@ -320,6 +323,10 @@ You can specify the day of week to run: ```ruby every(1.week, 'myjob', :at => 'Monday 16:20') +# This runs every Monday at 16:20 + +every(1.hour, 'myjob', :at => 'Monday **:**') +# This runs every hour only on Mondays ``` If another task is already running at the specified time, clockwork will skip execution of the task with the `:at` option. diff --git a/lib/clockwork/at.rb b/lib/clockwork/at.rb index 19ca4f9..39113cc 100644 --- a/lib/clockwork/at.rb +++ b/lib/clockwork/at.rb @@ -12,6 +12,12 @@ class FailedToParse < StandardError; end def self.parse(at) return unless at case at + when /\A([[:alpha:]]+)\s\*{1,2}:\*{1,2}\z/ + if wday = WDAYS[$1] + new(NOT_SPECIFIED, NOT_SPECIFIED, wday) + else + raise FailedToParse, at + end when /\A([[:alpha:]]+)\s(.*)\z/ if wday = WDAYS[$1] parsed_time = parse($2)