Skip to content

Commit

Permalink
add ability to call proc to set processing queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ncliffor committed Jul 19, 2017
1 parent a7abe6b commit e777b58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/dalliance.rb
Expand Up @@ -201,10 +201,18 @@ def pending_or_processing?
pending? || processing?
end

def processing_queue
if self.class.dalliance_options[:queue].respond_to?(:call)
self.class.instance_exec self, &dalliance_options[:queue]
else
self.class.dalliance_options[:queue]
end
end

#Force backgound_processing w/ true
def dalliance_background_process(backgound_processing = nil)
if backgound_processing || (backgound_processing.nil? && self.class.dalliance_options[:background_processing])
self.class.dalliance_options[:worker_class].enqueue(self, self.class.dalliance_options[:queue])
self.class.dalliance_options[:worker_class].enqueue(self, processing_queue)
else
dalliance_process(false)
end
Expand Down
26 changes: 26 additions & 0 deletions spec/dalliance/dalliance_spec.rb
Expand Up @@ -24,4 +24,30 @@
expect(DallianceModel.human_attribute_name(:dalliance_status)).to eq ('Status')
end
end

context "processing_queue" do
before do
DallianceModel.dalliance_options[:queue] = queue
end

context "string" do
let(:queue) { 'dalliance_2'}

specify{ expect(subject.processing_queue).to eq(queue) }
end

context "proc" do
context "w/o args" do
let(:queue) { Proc.new{ 'dalliance_2' } }

specify{ expect(subject.processing_queue).to eq(queue.call) }
end

context "w/ args" do
let(:queue) { Proc.new{ |a,b,c| 'dalliance_2' } }

specify{ expect(subject.processing_queue).to eq(queue.call) }
end
end
end
end

0 comments on commit e777b58

Please sign in to comment.