Skip to content

Commit

Permalink
Marshal runner list so ActiveJob can handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jun 25, 2015
1 parent ee5f83f commit 4c4e174
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/jobs/create_derivatives_job.rb
@@ -1,8 +1,9 @@
class CreateDerivativesJob < ActiveJob::Base
queue_as :low

def perform(id, runner)
def perform(id, runner_marshalled)
asset = GenericAsset.find(id)
runner = Marshal.load(runner_marshalled)
runner.run(asset)
end
end
4 changes: 3 additions & 1 deletion lib/oregon_digital/derivatives/delayed_runner.rb
Expand Up @@ -4,7 +4,9 @@ class DelayedRunner
delegate :to_a, :to => :runner

def run(asset)
job_factory.perform_later(asset.id, runner)
# Have to marshal the runner because ActiveJob doesn't, and there's no
# unique ID for them.
job_factory.perform_later(asset.id, Marshal.dump(runner))
end

class Factory
Expand Down
4 changes: 3 additions & 1 deletion spec/jobs/create_derivatives_job_spec.rb
Expand Up @@ -10,10 +10,12 @@
id = "1"
asset = instance_double(GenericAsset)
allow(GenericAsset).to receive(:find).with(id).and_return(asset)
marshalled_runner = double("marshalled")
runner = instance_double(OregonDigital::Derivatives::Runners::RunnerList)
allow(runner).to receive(:run).with(asset)
allow(Marshal).to receive(:load).with(marshalled_runner).and_return(runner)

subject.perform_now(id, runner)
subject.perform_now(id, marshalled_runner)

expect(runner).to have_received(:run).with(asset)
end
Expand Down
4 changes: 3 additions & 1 deletion spec/oregon_digital/derivatives/delayed_runner_spec.rb
Expand Up @@ -10,10 +10,12 @@
it "should run it on the job factory" do
asset = instance_double(GenericAsset, :id => double("id"))
allow(job_factory).to receive(:perform_later)
marshalled_runner = double("marshalled")
allow(Marshal).to receive(:dump).with(runner).and_return(marshalled_runner)

subject.run(asset)

expect(job_factory).to have_received(:perform_later).with(asset.id, runner)
expect(job_factory).to have_received(:perform_later).with(asset.id, marshalled_runner)
end
end
end
Expand Down

0 comments on commit 4c4e174

Please sign in to comment.