mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Move to instance method and document usage
This commit is contained in:
parent
f3a9ad7057
commit
afb3d4f9e5
8 changed files with 30 additions and 9 deletions
25
README.md
25
README.md
|
@ -11,6 +11,27 @@ one of the most common jobs in a modern web application: Sending emails outside
|
|||
of the request-response cycle, so the user doesn't have to wait on it.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Declare a job like so:
|
||||
|
||||
```ruby
|
||||
class MyJob < ActiveJob::Base
|
||||
def perform(record)
|
||||
record.do_work
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Enqueue a job like so:
|
||||
|
||||
```ruby
|
||||
MyJob.enqueue record
|
||||
```
|
||||
|
||||
That's it!
|
||||
|
||||
|
||||
## GlobalID support
|
||||
|
||||
Active Job supports GlobalID serialization for parameters. This makes it possible
|
||||
|
@ -19,7 +40,7 @@ you then have to manually deserialize. Before, jobs would look like this:
|
|||
|
||||
```ruby
|
||||
class TrashableCleanupJob
|
||||
def self.perfom(trashable_class, trashable_id, depth)
|
||||
def perfom(trashable_class, trashable_id, depth)
|
||||
trashable = trashable_class.constantize.find(trashable_id)
|
||||
trashable.cleanup(depth)
|
||||
end
|
||||
|
@ -30,7 +51,7 @@ Now you can simply do:
|
|||
|
||||
```ruby
|
||||
class TrashableCleanupJob
|
||||
def self.perfom(trashable, depth)
|
||||
def perfom(trashable, depth)
|
||||
trashable.cleanup(depth)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module ActiveJob
|
|||
|
||||
class JobWrapper
|
||||
def perform(job, *args)
|
||||
job.perform *Parameters.deserialize(args)
|
||||
job.new.perform *Parameters.deserialize(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module ActiveJob
|
|||
class InlineAdapter
|
||||
class << self
|
||||
def queue(job, *args)
|
||||
job.perform *Parameters.deserialize(args)
|
||||
job.new.perform *Parameters.deserialize(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ module ActiveJob
|
|||
end
|
||||
|
||||
def perform(job_name, *args)
|
||||
job_name.constantize.perform *Parameters.deserialize(args)
|
||||
job_name.constantize.new.perform *Parameters.deserialize(args)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module ActiveJob
|
|||
include Sidekiq::Worker
|
||||
|
||||
def perform(job_name, *args)
|
||||
job_name.constantize.perform *Parameters.deserialize(args)
|
||||
job_name.constantize.new.perform *Parameters.deserialize(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module ActiveJob
|
|||
include SuckerPunch::Job
|
||||
|
||||
def perform(job_name, *args)
|
||||
job_name.perform *Parameters.deserialize(args)
|
||||
job_name.new.perform *Parameters.deserialize(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class GidJob < ActiveJob::Base
|
||||
def self.perform(person)
|
||||
def perform(person)
|
||||
$BUFFER << "Person with ID: #{person.id}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class HelloJob < ActiveJob::Base
|
||||
def self.perform(greeter = "David")
|
||||
def perform(greeter = "David")
|
||||
$BUFFER << "#{greeter} says hello"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue