Skip to content

Commit

Permalink
merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jGRUBBS committed Jun 30, 2014
2 parents d72ca04 + b7f47b5 commit 0352a0c
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 86 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*.DS_Store

pkg
144 changes: 75 additions & 69 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
PATH
remote: .
specs:
delayed_cron (0.2.1)
delayed_cron (0.2.2)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.4)
actionpack (= 4.0.4)
actionmailer (4.1.2)
actionpack (= 4.1.2)
actionview (= 4.1.2)
mail (~> 2.5.4)
actionpack (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
erubis (~> 2.7.0)
actionpack (4.1.2)
actionview (= 4.1.2)
activesupport (= 4.1.2)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
activerecord (4.0.4)
activemodel (= 4.0.4)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.4)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.4)
actionview (4.1.2)
activesupport (= 4.1.2)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.2)
activesupport (= 4.1.2)
builder (~> 3.1)
activerecord (4.1.2)
activemodel (= 4.1.2)
activesupport (= 4.1.2)
arel (~> 5.0.0)
activesupport (4.1.2)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.2)
atomic (1.1.15)
builder (3.1.4)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
celluloid (0.15.2)
timers (~> 1.1.0)
codeclimate-test-reporter (0.3.0)
simplecov (>= 0.7.1, < 1.0.0)
columnize (0.3.6)
connection_pool (1.2.0)
debugger (1.6.6)
columnize (0.8.9)
connection_pool (2.0.0)
debugger (1.6.8)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.2)
debugger-ruby_core_source (~> 1.3.5)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.2)
delayed_job (4.0.0)
activesupport (>= 3.0, < 4.1)
debugger-ruby_core_source (1.3.5)
delayed_job (4.0.2)
activesupport (>= 3.0, < 4.2)
diff-lcs (1.2.5)
docile (1.1.3)
docile (1.1.5)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.9)
Expand All @@ -57,52 +58,54 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (4.7.5)
minitest (5.3.5)
mono_logger (1.1.0)
multi_json (1.9.0)
polyglot (0.3.4)
multi_json (1.10.1)
polyglot (0.3.5)
rack (1.5.2)
rack-protection (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.4)
actionmailer (= 4.0.4)
actionpack (= 4.0.4)
activerecord (= 4.0.4)
activesupport (= 4.0.4)
rails (4.1.2)
actionmailer (= 4.1.2)
actionpack (= 4.1.2)
actionview (= 4.1.2)
activemodel (= 4.1.2)
activerecord (= 4.1.2)
activesupport (= 4.1.2)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.4)
sprockets-rails (~> 2.0.0)
railties (4.0.4)
actionpack (= 4.0.4)
activesupport (= 4.0.4)
railties (= 4.1.2)
sprockets-rails (~> 2.0)
railties (4.1.2)
actionpack (= 4.1.2)
activesupport (= 4.1.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.1)
redis (3.0.7)
redis-namespace (1.4.1)
redis (~> 3.0.4)
resque (1.25.1)
rake (10.3.2)
redis (3.1.0)
redis-namespace (1.5.0)
redis (~> 3.0, >= 3.0.4)
resque (1.25.2)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.5)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.1)
rspec-expectations (2.99.1)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-sidekiq (1.0.0)
rspec (>= 2.0.0)
rspec-mocks (2.99.1)
rspec-sidekiq (1.1.0)
rspec (~> 2.0)
sidekiq (>= 2.4.0)
sidekiq (2.17.6)
sidekiq (3.1.4)
celluloid (>= 0.15.2)
connection_pool (>= 1.0.0)
connection_pool (>= 2.0.0)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
Expand All @@ -111,29 +114,31 @@ GEM
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
sinatra (1.4.4)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sprockets (2.12.0)
sprockets (2.12.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
sprockets-rails (2.1.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
thor (0.18.1)
thread_safe (0.2.0)
atomic (>= 1.1.7, < 2)
sucker_punch (1.1)
celluloid (~> 0.15.2)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timecop (0.7.1)
timers (1.1.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.39)
tzinfo (1.2.1)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)

Expand All @@ -150,4 +155,5 @@ DEPENDENCIES
rspec
rspec-sidekiq
sidekiq
sucker_punch
timecop
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
[![Code Climate](https://codeclimate.com/github/sellect/delayed_cron.png?branch=master)](https://codeclimate.com/github/sellect/delayed_cron)

# DelayedCron
run cron jobs with sidekiq, delayed_job, or resque
run cron jobs with sidekiq, delayed_job, resque, or sucker_punch

### DEPENDENCIES:
- background process handler: sidekiq, delayed_job, or resque
- background process handler: sidekiq, delayed_job, resque, or sucker_punch

### INSTALL

```ruby
gem "delayed_cron", "0.2.1"
gem "delayed_cron", "0.2.2"
```

### USE IN MODEL
Expand Down
5 changes: 3 additions & 2 deletions delayed_cron.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ Gem::Specification.new do |s|
s.version = DelayedCron::VERSION

s.authors = ["Justin Grubbs"]
s.summary = %q{Run your cron jobs with sidekiq, delayed_job, or resque.}
s.description = %q{Run your cron jobs with sidekiq, delayed_job, or resque.}
s.summary = %q{Run your cron jobs with sidekiq, delayed_job, resque, or sucker_punch.}
s.description = %q{Run your cron jobs with sidekiq, delayed_job, resque, or sucker_punch.}
s.email = %q{[email protected]}
s.homepage = %q{http://github.com/sellect/delayed_cron}

s.add_development_dependency "delayed_job"
s.add_development_dependency "resque"
s.add_development_dependency "sidekiq"
s.add_development_dependency "sucker_punch"
s.add_development_dependency "rspec"
s.add_development_dependency "rails"
s.add_development_dependency "debugger"
Expand Down
14 changes: 8 additions & 6 deletions lib/delayed_cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def define_cron_jobs
end

def processor
return DelayedCron::Jobs::DelayedJob if defined? ::Delayed::Job
return DelayedCron::Jobs::Resque if defined? ::Resque
return DelayedCron::Jobs::Sidekiq if defined? ::Sidekiq
return DelayedCron::Jobs::DelayedJob if defined? ::Delayed::Job
return DelayedCron::Jobs::Resque if defined? ::Resque
return DelayedCron::Jobs::Sidekiq if defined? ::Sidekiq
return DelayedCron::Jobs::SuckerPunch if defined? ::SuckerPunch
end

def schedule(klass, method_name, options)
Expand Down Expand Up @@ -56,9 +57,9 @@ def adjusted_date(date, time_string)
def parse_time(time_array)
{
hours: time_array[0],
mins: time_array[1],
secs: time_array[2] || 0,
tz: time_array[3] || Time.now.strftime("%z").to_i
mins: time_array[1],
secs: time_array[2] || 0,
tz: time_array[3] || Time.now.strftime("%z").to_i
}
end

Expand All @@ -73,6 +74,7 @@ def self.included(base)
module ClassMethods

def cron_job(name, options = { interval: DelayedCron.default_interval })
return false if options.delete(:if) == false
DelayedCron.schedule(self.name.to_s, name, options)
end

Expand Down
1 change: 1 addition & 0 deletions lib/delayed_cron/jobs/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'sidekiq/worker'
require 'sidekiq/api'

module DelayedCron
module Jobs
Expand Down
29 changes: 29 additions & 0 deletions lib/delayed_cron/jobs/sucker_punch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'sucker_punch'

module DelayedCron
module Jobs
class SuckerPunch
include ::SuckerPunch::Job

def self.enqueue_delayed_cron(klass, method_name, options)
unless scheduled?(klass)
options.symbolize_keys!
self.new.later(options[:interval], klass, method_name, options)
end
end

def self.scheduled?(klass)
::SuckerPunch::Queue.new(klass).registered?
end

def perform(klass, method_name, options)
DelayedCron.process_job(klass, method_name, options)
end

def later(sec, *args)
after(sec) { perform(*args) }
end

end
end
end
2 changes: 1 addition & 1 deletion lib/delayed_cron/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DelayedCron
VERSION = "0.2.1"
VERSION = "0.2.2"
end
24 changes: 20 additions & 4 deletions spec/delayed_cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,26 @@
end

describe "cron_job" do
it "schedules cron jobs found in a model" do
klass, name = "SomeClass", "some_method"
DelayedCron.should_receive(:schedule).with(klass, name, {})
build_class(klass, name)
context 'if not present' do
it "schedules cron jobs found in a model" do
klass, name = "SomeClass", "some_method"
DelayedCron.should_receive(:schedule).with(klass, name, {})
build_class(klass, name)
end
end
context 'if present and true' do
it "schedules cron jobs found in a model" do
klass, name = "SomeClass", "some_method"
DelayedCron.should_receive(:schedule).with(klass, name, {})
build_class(klass, name, {if: true})
end
end
context 'if present and false' do
it "schedules cron jobs found in a model" do
klass, name = "SomeClass", "some_method"
DelayedCron.should_not_receive(:schedule).with(klass, name, {})
build_class(klass, name, {if: false})
end
end
end

Expand Down

0 comments on commit 0352a0c

Please sign in to comment.