Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: force batch callback belt #17

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sidekiq/belt/pro/failed_batch_remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.registered(app)

content.gsub!(
"</td>\n </tr>\n <% end %>",
"</td>\n<td>#{REMOVE_BUTTON}</td>\n </tr>\n <% end %>"
"</td>\n<td>#{REMOVE_BUTTON}</td>\n </tr>\n <% end %>"
)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq/belt/pro/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "sidekiq"

require_relative "failed_batch_remove"
require_relative 'force_batch_callback'

module Sidekiq
module Belt
Expand All @@ -14,6 +15,7 @@ def self.use!(options = [:all])
all = options.include?(:all)

Sidekiq::Belt::Pro::FailedBatchRemove.use! if all || options.include?(:failed_batch_remove)
Sidekiq::Belt::Pro::ForceBatchCallback.use! if all || options.include?(:force_batch_callback)

true
end
Expand Down
58 changes: 58 additions & 0 deletions lib/sidekiq/belt/pro/force_batch_callback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require "sidekiq/web/helpers"

module Sidekiq
module Belt
module Pro
module ForceBatchCallback
module SidekiqForceBatchCallback
def self.action_button(action)
action_name = "force_#{action}"
action_chars = action.chars
action_button = action_chars.capitalize
<<~ERB
<form action="<%= root_path %>batches/<%= @batch.bid %>/force_callback/#{action}" method="post">
<%= csrf_tag %>
<input class="btn btn-danger" type="submit" name="#{action_name}" value="<%= t('#{action_button}') %>"
data-confirm="Do you want to force the #{action} callback for batch <%= @batch.bid %>? <%= t('AreYouSure') %>" />
</form>
ERB
end

def self.registered(app)
app.replace_content("/batches/:bid") do |content|
content.sub!(/(<\/tbody>)/) do |match|
<<-HTML
<tr>
<th><%= t("Force Action") %></th>
<td>
<div style="display: flex;">
#{action_button('success')}
#{action_button('complete')}
#{action_button('death')}
</div>
</td>
</tr>
#{match}
HTML
end
end

app.post("/batches/:bid/force_callback/:action") do
Sidekiq::Batch::Callback.perform_inline(params[:action], params[:bid])

return redirect "#{root_path}batches"
end
end
end

def self.use!
require("sidekiq/web")

Sidekiq::Web.register(Sidekiq::Belt::Pro::ForceBatchCallback::SidekiqForceBatchCallback)
end
end
end
end
end
Loading