Module: Sidekiq::Belt::Pro::ForceBatchCallback::SidekiqForceBatchCallback

Defined in:
lib/sidekiq/belt/pro/force_batch_callback.rb

Class Method Summary collapse

Class Method Details

.action_button(action) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/sidekiq/belt/pro/force_batch_callback.rb', line 10

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

.registered(app) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sidekiq/belt/pro/force_batch_callback.rb', line 20

def self.registered(app)
  app.replace_content("/batches/:bid") do |content|
    content.sub!(%r{(</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(route_params(:action), route_params(:bid))

    return redirect "#{root_path}batches"
  end
end