Skip to content

Commit

Permalink
Add success_handler to give subclass control over success (#338)
Browse files Browse the repository at this point in the history
* Add success_handler to give subclass control over success

- For example, retaining completed request and mark them for completion instead of deleting them.

Co-authored-by: Maher Hawash <gmhawash@gmail.com>
  • Loading branch information
ukd1 and gmhawash committed May 18, 2022
1 parent bad7fd1 commit 8484634
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/queue_classic/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def process(queue, job)
finished = false
begin
call(job).tap do
queue.delete(job[:id])
handle_success(queue, job)
finished = true
end
rescue StandardError, ScriptError, NoMemoryError => e
Expand Down Expand Up @@ -139,6 +139,10 @@ def call(job)
receiver.send(message, *args)
end

def handle_success(queue, job)
queue.delete(job[:id])
end

# This method will be called when a StandardError, ScriptError or
# NoMemoryError is raised during the execution of the job.
def handle_failure(job,e)
Expand Down

0 comments on commit 8484634

Please sign in to comment.