Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: master
...
compare: master
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 29 additions and 10 deletions.
  1. +18 −3 README.markdown
  2. +7 −3 lib/repeated_job.rb
  3. +4 −4 spec/repeated_job_spec.rb
21 README.markdown
View
@@ -1,13 +1,28 @@
Repeated::Job
=============
-Repeated::Job will use Delayed::Job to call `rake cron` on your app at an
-interval you specify.
+Repeated::Job was written by David Dollar, original here - https://github.com/ddollar/repeated_job
+
+Changes
+=======
+
+In this fork, these are the interesting changes:
+
+* Changed scheduling to round to nearest interval. So, tasks that run every 5 minutes will actually run on the :00's and :05's - instead of 5 mins from whenever your app server happens to have started.
+* Changed the rake task that gets run to 'repeated' instead of 'cron' - I want to preserve the ability to run 'cron' on heroku platform unrelated to these repeated jobs.
+* Updated code to avoid some Delayed::Job warnings.
+
+Overview
+========
+
+Repeated::Job will use Delayed::Job to call `rake repeated` on your app at an interval you specify.
+
+Internally, it's just constantly scheduling Delayed Jobs to call itself, and then does nothing but call your rake tasks and schedule itself again.
Installation
============
- script/plugin install git://github.com/ddollar/repeated_job.git
+ script/plugin install git://github.com/mjankowski/repeated_job.git
Setup
=====
10 lib/repeated_job.rb
View
@@ -1,4 +1,4 @@
-require "active_support"
+require "active_support/time"
require "rake"
module Repeated
@@ -13,12 +13,16 @@ def initialize
def perform
schedule_next
- Rake::Task["cron"].execute
+ Rake::Task["repeated"].execute
end
def schedule_next
Delayed::Job.delete_all "handler like '%Repeated::Job%'"
- Delayed::Job.enqueue self, priority, interval.minutes.from_now.getutc
+ Delayed::Job.enqueue self, :priority => priority, :run_at => rounded_time(interval.minutes).getutc
+ end
+
+ def rounded_time(seconds = 60)
+ Time.at((Time.now.to_f / seconds).ceil * seconds)
end
end
8 spec/repeated_job_spec.rb
View
@@ -37,10 +37,10 @@
Delayed::Job.should_receive(:delete_all).with(/Repeated::Job/)
- Delayed::Job.should_receive(:enqueue) do |object, priority, scheduled|
+ Delayed::Job.should_receive(:enqueue) do |object, options|
object.should == @repeated
- priority.should == @repeated.priority
- (scheduled - Time.now).should be_close(300, 5)
+ options[:priority].should == @repeated.priority
+ options[:run_at].should == Time.at((Time.now.to_f / 5.minutes).ceil * 5.minutes).getutc
end
@repeated.schedule_next
@@ -48,7 +48,7 @@
it "should schedule itself again when executing" do
@was_run = false
- task(:cron) { @was_run = true }
+ task(:repeated) { @was_run = true }
@repeated.should_receive(:schedule_next)
@repeated.perform

No commit comments for this range

Something went wrong with that request. Please try again.