Skip to content

Commit

Permalink
Merge pull request rubyonjets#596 from jtadeulopes/issue-595-fix-job-…
Browse files Browse the repository at this point in the history
…serializer

Serialize job data correctly
  • Loading branch information
tongueroo authored Oct 16, 2021
2 parents f5851b6 + 38f1ff9 commit 5247405
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jets/job/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def process(event, context, meth)
end

def perform_now(meth, event={}, context={})
new(event, context, meth).send(meth)
new(event.try(:to_unsafe_h), context, meth).send(meth)
end

def perform_later(meth, event={}, context={})
if on_lambda?
function_name = "#{self.to_s.underscore}-#{meth}"
call = Jets::Commands::Call.new(function_name, JSON.dump(event), invocation_type: "Event")
call = Jets::Commands::Call.new(function_name, JSON.dump(event.try(:to_unsafe_h)), invocation_type: "Event")
call.run
else
puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead."
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/jets/job/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
HardJob.perform_later(:dig, {})
expect(Jets::Commands::Call).to have_received(:new)
end

context 'when using ActionController::Parameters object' do
let(:event) { ActionController::Parameters.new(key1: "value1") }

it "perform_now" do
resp = HardJob.perform_now(:dig, event)
expect(resp).to eq(done: "digging")
end

it "perform_later" do
allow(Jets::Commands::Call).to receive(:new).and_return(null)
allow(HardJob).to receive(:on_lambda?).and_return(true)
expect(Jets::Commands::Call).to receive(:new).with('hard_job-dig', "{\"key1\":\"value1\"}", invocation_type: "Event")
HardJob.perform_later(:dig, event)
end
end
end

context EasyJob do
Expand Down

0 comments on commit 5247405

Please sign in to comment.