Skip to content

Commit

Permalink
* updated documentation
Browse files Browse the repository at this point in the history
* removed auto_load fields in favour of resque_schedule method
  • Loading branch information
and9000 committed Nov 1, 2021
1 parent 3af21bc commit e1c9334
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 94 deletions.
1 change: 0 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ Resque Scheduler authors
- sawanoboly
- serek
- iloveitaly
- Andrea Lorenzetti
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,18 @@ Resque::Scheduler.auto_load = 'path/to/*_job.rb'
Auto load enables a job to declare it's scheduling. In order to do that file must follow `snake_case` convention for filename and `CamelCase` for class name. It also must include `Resque::Scheduler::Job` and declares it's schedule:

```ruby
cron '*/2 * * * *'
queue 'default'
resque_schedule cron: '*/2 * * * *'
```

All options available:

```ruby
cron '* */3 * * *' # use cron or every option, don't use both
every '3d' # use every or cron option, don't use both
queue 'default'
args 'custom arg'
description 'Nice description'
resque_schedule(
cron: '* */3 * * *', # use cron or every option, don't use both
every: '3d', # use every or cron option, don't use both
args: 'Custom arg',
description: 'Nice description'
)
```

Job's example:
Expand All @@ -439,10 +439,9 @@ require 'resque/scheduler/job'
class MyGreatJob
include Resque::Scheduler::Job
cron '*/2 * * * *'
queue 'default'
args 'args'
description 'description'
@queue = :default
resque_schedule cron: '*/2 * * * *', args: 'args', description: 'description'
end
```
Expand Down
15 changes: 0 additions & 15 deletions lib/resque/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,6 @@ def load_schedule!

Dir[auto_load.to_s].each do |file|
require File.absolute_path(file)
name = File.basename(file, '.rb')
begin
klass = Resque::Scheduler::Util.constantize(name)
rescue NameError
log! "Can't load file #{file}"
end
load_schedule_job(
name,
'class' => klass.name,
'cron' => klass.respond_to?(:cron) ? klass.cron : nil,
'every' => klass.respond_to?(:every) ? klass.every : nil,
'queue' => klass.respond_to?(:queue) ? klass.queue : nil,
'args' => klass.respond_to?(:args) ? klass.args : nil,
'description' => klass.respond_to?(:description) ? klass.description : nil
) if klass
end

Resque.redis.del(:schedules_changed) if am_master && dynamic
Expand Down
33 changes: 10 additions & 23 deletions lib/resque/scheduler/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,16 @@ def included(base)
end

module ClassMethods
def cron(value = nil)
return @cron ||= nil if value.nil?
@cron = value
end

def every(value = nil)
return @every ||= nil if value.nil?
@every = value
end

def queue(value = nil)
return @queue ||= nil if value.nil?
@queue = value
end

def args(value = nil)
return @args ||= nil if value.nil?
@args = value
end

def description(value = nil)
return @description ||= nil if value.nil?
@description = value
def resque_schedule(cron: nil, every: nil, args: nil, description: nil)
Resque::Scheduler.load_schedule_job(
name,
'class' => name,
'cron' => cron,
'every' => every,
'queue' => @queue,
'args' => args,
'description' => description
)
end
end
end
Expand Down
7 changes: 3 additions & 4 deletions test/fixtures/valid_cron_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
class ValidCronJob
include Resque::Scheduler::Job

cron '*/2 * * * *'
queue 'default'
args 'args'
description 'description'
@queue = :default

resque_schedule cron: '*/2 * * * *', args: 'args', description: 'description'
end
7 changes: 3 additions & 4 deletions test/fixtures/valid_every_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
class ValidEveryJob
include Resque::Scheduler::Job

every '1d'
queue 'default'
args 'args'
description 'description'
@queue = :default

resque_schedule every: '1d', args: 'args', description: 'description'
end
33 changes: 0 additions & 33 deletions test/job_test.rb

This file was deleted.

6 changes: 3 additions & 3 deletions test/scheduler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@

assert_equal(2, Resque::Scheduler.rufus_scheduler.jobs.size)
assert_equal(2, Resque::Scheduler.scheduled_jobs.size)
%w(valid_cron_job valid_every_job).each do |job_name|
%w(ValidCronJob ValidEveryJob).each do |job_name|
assert Resque::Scheduler.scheduled_jobs.keys.include?(job_name)
end

cron_job = Resque::Scheduler.scheduled_jobs['valid_cron_job']
cron_job = Resque::Scheduler.scheduled_jobs['ValidCronJob']
assert_equal('*/2 * * * *', cron_job.original)

every_job = Resque::Scheduler.scheduled_jobs['valid_every_job']
every_job = Resque::Scheduler.scheduled_jobs['ValidEveryJob']
assert_equal('1d', every_job.original)
end

Expand Down

0 comments on commit e1c9334

Please sign in to comment.