Module: Sidekiq::Belt::Ent::PeriodicRun::SidekiqLoopsPeriodicRun

Defined in:
lib/sidekiq/belt/ent/periodic_run.rb

Constant Summary collapse

FORCE_RUN_BUTTON =
<<~ERB
  name="enqueue" data-confirm="Enqueue the job <%= loup.klass %>? <%= t('AreYouSure') %>"
ERB
FORCE_RUN_SINGLE_PAGE =
<<~ERB
      <tr>
      <th><%= t('Force Run') %></th>
      <td>
        <form action="<%= root_path %>loops/<%= @loop.lid %>/run" method="post">
          <%= csrf_tag %>
          <input class="btn btn-danger" type="submit" name="run" value="<%= t('Run now') %>"
            data-confirm="Run the job <%= @loop.klass %>? <%= t('AreYouSure') %>" />
        </form>
      </td>
    </tr>
  </tbody>
ERB

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidekiq/belt/ent/periodic_run.rb', line 38

def self.registered(app)
  app.replace_content("/loops") do |content|
    content.gsub!("name=\"enqueue\"", FORCE_RUN_BUTTON)
  end

  app.replace_content("/loops/:lid") do |content|
    i = 0

    content.gsub!("</tbody>") do |match|
      if i.zero?
        i += 1

        FORCE_RUN_SINGLE_PAGE
      else
        match
      end
    end
  end

  app.post("/loops/:lid/run") do
    Sidekiq::Periodic::Loop.new(route_params(:lid)).run

    return redirect "#{root_path}loops"
  end
end