Merge pull request #36 from preisanalytics/jhuebl_add_data_to_scheduled_job_20160113

Add the possibility to schedule jobs with arguments
This commit is contained in:
Dzmitry Plashchynski
2016-01-16 01:18:22 +02:00
7 changed files with 55 additions and 17 deletions

View File

@@ -61,11 +61,11 @@ class TestJob < ActiveJob::Base
end
```
The ActiveJob jobs is convenient because you can use one job in both periodic and enqueued ways. But Active Job is not required. Any class can be used as a crono job if it implements a method `perform` without arguments:
The ActiveJob jobs is convenient because you can use one job in both periodic and enqueued ways. But Active Job is not required. Any class can be used as a crono job if it implements a method `perform`:
```ruby
class TestJob # This is not an Active Job job, but pretty legal Crono job.
def perform
def perform(*args)
# put you scheduled code here
# Comments.deleted.clean_up...
end
@@ -124,6 +124,13 @@ The `at` can be a Hash:
Crono.perform(TestJob).every 1.day, at: {hour: 12, min: 15}
```
You can schedule a job with arguments, which can contain objects that can be
serialized using JSON.generate
```ruby
Crono.perform(TestJob, 'some', 'args').every 1.day, at: {hour: 12, min: 15}
```
#### Run daemon
To run Crono daemon, in your Rails project root directory: