Skip to content

Commit

Permalink
Merge pull request #788 from NREL/too_many_requeues
Browse files Browse the repository at this point in the history
add requeue_failed API to requeue the Failed resque jobs but in the :…
  • Loading branch information
brianlball authored Aug 16, 2024
2 parents f590985 + 8103a82 commit ca705ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ def prune_resque_workers
end
end

# POST /jobs/requeue_failed
def requeue_failed
Rails.logger.warn "Requeueing Failed Jobs to 'requeued' Queue"

requeued_count = 0

Resque::Failure.each do |id, failed_job|
payload = failed_job['payload']
job_class = payload['class']
job_args = payload['args']

# Requeue the job to the 'requeued' queue
Resque.enqueue_to('requeued', job_class.constantize, *job_args)
# Remove the job from the failed queue
Resque::Failure.remove(id)
requeued_count += 1
end

Rails.logger.info "#{requeued_count} jobs successfully requeued to 'requeued' queue by requeue_failed"

respond_to do |format|
format.html { redirect_to admin_index_path, notice: "#{requeued_count} Resque jobs requeued." }
format.json { render json: { message: "#{requeued_count} jobs requeued to 'requeued' queue" }, status: :ok }
end
end

def backup_database
logger.info params
write_and_send_data
Expand Down
4 changes: 4 additions & 0 deletions server/app/views/admin/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<!-- Link to prune dead Resque workers -->
<%= link_to 'Prune Dead Resque Workers', prune_resque_workers_admin_index_path, method: :post, class: "btn btn-mini btn-danger", data: { confirm: 'Are you sure you want to prune dead Resque workers?' } %>
</div>
<div class="span3 pad-bottom-20">
<!-- Link to requeue failed Resque workers -->
<%= link_to 'Requeue Failed Resque Workers', requeue_failed_admin_index_path, method: :post, class: "btn btn-mini btn-danger", data: { confirm: 'Are you sure you want to requeue failed Resque workers?' } %>
</div>
</div>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions server/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
get :backup_database
post :restore_database
post :prune_resque_workers
post :requeue_failed
end
end

Expand Down

0 comments on commit ca705ea

Please sign in to comment.