mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simplest job and inline queue
This commit is contained in:
parent
60d13d638e
commit
08a2ba99e0
4 changed files with 37 additions and 2 deletions
|
@ -1,4 +1,11 @@
|
|||
require 'active_job/queue_adapters/inline_queue'
|
||||
|
||||
module ActiveJob
|
||||
class Base
|
||||
class << self
|
||||
def enqueue(*args)
|
||||
ActiveJob::QueueAdapters::InlineQueue.queue self, *args
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
lib/active_job/queue_adapters/inline_queue.rb
Normal file
11
lib/active_job/queue_adapters/inline_queue.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module ActiveJob
|
||||
module QueueAdapters
|
||||
class InlineQueue
|
||||
class << self
|
||||
def queue(job, *args)
|
||||
job.perform *args
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,19 @@
|
|||
require 'helper'
|
||||
require 'jobs/hello_job'
|
||||
|
||||
|
||||
class QueuingTest < ActiveSupport::TestCase
|
||||
test 'the truth' do
|
||||
assert true
|
||||
setup do
|
||||
$BUFFER = []
|
||||
end
|
||||
|
||||
test 'run queued job' do
|
||||
HelloJob.enqueue
|
||||
assert_equal "David says hello", $BUFFER.pop
|
||||
end
|
||||
|
||||
test 'run queued job with parameters' do
|
||||
HelloJob.enqueue "Jamie"
|
||||
assert_equal "Jamie says hello", $BUFFER.pop
|
||||
end
|
||||
end
|
||||
|
|
5
test/jobs/hello_job.rb
Normal file
5
test/jobs/hello_job.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class HelloJob < ActiveJob::Base
|
||||
def self.perform(greeter = "David")
|
||||
$BUFFER << "#{greeter} says hello"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue