# frozen_string_literal: true require "sidekiq/web/helpers" module Sidekiq module Belt module Ent module PeriodicRun def run args = begin JSON.parse(options)["args"] rescue StandardError {} end Module.const_get(klass).perform_async(*args) end module SidekiqLoopsPeriodicRun FORCE_RUN_BUTTON = <<~ERB
<%= csrf_tag %>
ERB FORCE_RUN_SINGLE_PAGE = <<~ERB <%= t('Force Run') %>
<%= csrf_tag %>
ERB def self.registered(app) app.replace_content("/loops") do |content| # Add the top of the table content.gsub!("\n ", "<%= t('Force Run') %>\n ") # Add the run button content.gsub!( "\n \n <% end %>", "\n#{FORCE_RUN_BUTTON}\n \n <% end %>" ) end app.replace_content("/loops/:lid") do |content| i = 0 content.gsub!("") 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(params[:lid]).run return redirect "#{root_path}loops" end end end def self.use! require("sidekiq-ent/web") require("sidekiq-ent/periodic") require("sidekiq-ent/periodic/static_loop") Sidekiq::Web.register(Sidekiq::Belt::Ent::PeriodicRun::SidekiqLoopsPeriodicRun) Sidekiq::Periodic::Loop.prepend(Sidekiq::Belt::Ent::PeriodicRun) Sidekiq::Periodic::StaticLoop.prepend(Sidekiq::Belt::Ent::PeriodicRun) end end end end end