Skip to content

Commit 3347d17

Browse files
committed
Return a custom wrapped JobError with clean backtrace.
1 parent c3c9745 commit 3347d17

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

TODO.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ def _enqueue(job, send_message_opts = {})
2424
end
2525
```
2626

27-
* Use job's `attr_accessor :executions` vs `ApproximateReceiveCount`
2827
* Error handlers. Ensure we easily hook into Rollbar, etc.
29-
* Is `delete_message` message needed? Is 200 from consumer implied delete?
3028
* Can I set Rails tempalte `VisibilityTimeout` to just +1 of function timeout or full 43200?
31-
* Can I get rid of the Job re-raising and rely on change message visibility alone?
29+
* Do this in our gem. `ActiveJob::Base.logger = Logger.new(IO::NULL)`
3230

3331
## Doc Points
3432

@@ -60,7 +58,6 @@ DO I MIRROR or MIGRATE
6058
## Max Retries
6159

6260
* Max is twelve.
63-
*
6461

6562
## Migrating from Sidekiq
6663

lib/lambdakiq.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'active_job/queue_adapters'
55
require 'active_support/all'
66
require 'lambdakiq/version'
7+
require 'lambdakiq/error'
78
require 'lambdakiq/adapter'
89
require 'lambdakiq/client'
910
require 'lambdakiq/queue'

lib/lambdakiq/error.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Lambdakiq
2+
class Error < StandardError
3+
attr_reader :original_exception, :job
4+
5+
def initialize(error)
6+
@original_exception = error
7+
super(error.message)
8+
set_backtrace Rails.backtrace_cleaner.clean(error.backtrace)
9+
end
10+
end
11+
12+
class JobError < Error ; end
13+
end

lib/lambdakiq/job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def handler(event)
1010
jobs = records.map { |record| new(record) }
1111
jobs.each(&:perform)
1212
jwerror = jobs.detect{ |j| j.error }
13-
jwerror ? raise(jwerror.error) : true
13+
return unless jwerror
14+
raise JobError.new(jwerror.error)
1415
end
1516

1617
end

0 commit comments

Comments
 (0)