Skip to content

Commit 3997baa

Browse files
committed
update publish message
1 parent 8242c69 commit 3997baa

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

app/jobs/outboxer_integration/message/publish_job.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ def perform(args)
1616

1717
namespace, model, event = messageable_type.match(MESSAGEABLE_TYPE_REGEX).captures
1818
job_class_name = "#{namespace}::#{model}::#{event}Job"
19-
job_class = job_class_name.constantize
20-
job_class.perform_async({ 'id' => args['messageable_id'] })
19+
20+
begin
21+
job_class = job_class_name.constantize
22+
job_class.perform_async({ 'id' => args['messageable_id'] })
23+
rescue NameError
24+
# no-op
25+
end
2126
end
2227
end
2328
end

spec/jobs/outboxer_integration/message/publish_job_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ module Message
3535
}.to raise_error(StandardError, "Unexpected class name format: Wrong::Format::Test")
3636
end
3737
end
38+
39+
context 'when job class does not exist' do
40+
let(:args) do
41+
{
42+
'messageable_type' => 'Accountify::Models::Invoice::NonexistentEvent',
43+
'messageable_id' => '123'
44+
}
45+
end
46+
47+
it 'completes gracefully without raising an error' do
48+
allow_any_instance_of(String)
49+
.to receive(:constantize)
50+
.and_raise(NameError.new("uninitialized constant"))
51+
52+
expect {
53+
PublishJob.new.perform(args)
54+
}.not_to raise_error
55+
end
56+
end
3857
end
3958
end
4059
end

0 commit comments

Comments
 (0)