capture the current shard for jobs
including batch jobs test plan: * n/a without a sharding implementation Change-Id: Id4e8b8a72e71a21e0862fda27059f57412a80a53 Reviewed-on: https://gerrit.instructure.com/10165 Reviewed-by: Jon Jensen <jon@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
238f8056e0
commit
c8ee535354
|
@ -49,6 +49,12 @@ class Shard
|
|||
{}
|
||||
end
|
||||
|
||||
yaml_as "tag:instructure.com,2012:Shard"
|
||||
|
||||
def self.yaml_new(klass, tag, val)
|
||||
default
|
||||
end
|
||||
|
||||
module RSpec
|
||||
def self.included(klass)
|
||||
klass.before do
|
||||
|
|
|
@ -19,6 +19,11 @@ module Delayed
|
|||
class Job < ::ActiveRecord::Base
|
||||
include Delayed::Backend::Base
|
||||
set_table_name :delayed_jobs
|
||||
attr_writer :current_shard
|
||||
|
||||
def current_shard
|
||||
@current_shard || Shard.default
|
||||
end
|
||||
|
||||
# be aware that some strand functionality is controlled by triggers on
|
||||
# the database. see
|
||||
|
|
|
@ -33,6 +33,7 @@ module Delayed
|
|||
options[:payload_object] = object
|
||||
options[:queue] ||= Delayed::Worker.queue
|
||||
options[:max_attempts] ||= Delayed::Worker.max_attempts
|
||||
options[:current_shard] = Shard.current
|
||||
if options[:singleton]
|
||||
options[:strand] = options.delete :singleton
|
||||
self.transaction do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path("../spec_helper", __FILE__)
|
||||
require File.expand_path("../../../../../spec/sharding_spec_helper", __FILE__)
|
||||
|
||||
describe Delayed::Batch do
|
||||
before :each do
|
||||
|
@ -69,4 +69,28 @@ describe Delayed::Batch do
|
|||
Delayed::Job.count.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "delayed_jobs_shards" do
|
||||
it "should keep track of the current shard on child jobs" do
|
||||
shard = @shard1 || Shard.default
|
||||
shard.activate do
|
||||
Delayed::Batch.serial_batch {
|
||||
"string".send_later(:size).should be_true
|
||||
"string".send_later(:gsub, /./, "!").should be_true
|
||||
}
|
||||
end
|
||||
job = Delayed::Job.last
|
||||
job.current_shard.should == shard
|
||||
job.payload_object.jobs.first.current_shard.should == shard
|
||||
end
|
||||
end
|
||||
|
||||
describe "current_shard" do
|
||||
it_should_behave_like "delayed_jobs_shards"
|
||||
|
||||
context "sharding" do
|
||||
it_should_behave_like "sharding"
|
||||
it_should_behave_like "delayed_jobs_shards"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue