Skip to content

Commit

Permalink
Added button on periodic task page
Browse files Browse the repository at this point in the history
  • Loading branch information
dannnylo committed Oct 7, 2023
1 parent ec25d65 commit ffda7a2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
gem "rubocop-rake"
gem "rubocop-rspec"

gem 'byebug'
1 change: 0 additions & 1 deletion lib/sidekiq-belt.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/sidekiq/belt/community/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Belt
module Community
module Files
def self.use!(_options = [:all])

puts "Com FILES"

# all = options.include?(:all)
Expand Down
10 changes: 8 additions & 2 deletions lib/sidekiq/belt/community/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ def replace_content(path, &block)

module WebActionHelper
def render(engine, content, options = {})
path_info = ::Rack::Utils.unescape(env["PATH_INFO"])
begin
path_info = /"([^"]*)"/.match(block.source.to_s)[1]
rescue StandardError
path_info = nil
end

path_info ||= ::Rack::Utils.unescape(env["PATH_INFO"])

Sidekiq::ReplaceContents.blocks.fetch(path_info.to_s, []).each do |content_block|
content_block.call(content)
Expand All @@ -34,4 +40,4 @@ def render(engine, content, options = {})
end

Sidekiq::WebAction.prepend(Sidekiq::WebActionHelper)
end
end
5 changes: 3 additions & 2 deletions lib/sidekiq/belt/ent/periodic_pause.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'sidekiq-ent/periodic'
require 'sidekiq-ent/periodic/static_loop'

require "sidekiq-ent/periodic"
require "sidekiq-ent/periodic/static_loop"

module Sidekiq
module Belt
Expand Down
55 changes: 43 additions & 12 deletions lib/sidekiq/belt/ent/periodic_run.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true
require 'byebug'
require 'sidekiq/web/helpers'
require 'sidekiq-ent/web'
require 'sidekiq-ent/periodic'
require 'sidekiq-ent/periodic/static_loop'

require "byebug"
require "sidekiq/web/helpers"
require "sidekiq-ent/web"
require "sidekiq-ent/periodic"
require "sidekiq-ent/periodic/static_loop"

module Sidekiq
module Belt
Expand All @@ -20,24 +21,54 @@ def run
end

module SidekiqLoopsPeriodicRun
FORCE_RUN_BUTTON_ERB = <<~HTML
<form action="<%= root_path %>loops/<%= loup.lid %>/run" method="post">
<%= csrf_tag %>
<input class="btn btn-danger" type="submit" name="run" value="<%= t('Run now') %>"
data-confirm="Run the job <%= loup.klass %>? <%= t('AreYouSure') %>" />
</form>
HTML

FORCE_RUN_SINGLE_PAGE_ERB = <<~HTML
<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>
HTML

def self.registered(app)
app.replace_content("/loops") do |content|
# Add the top of the table
content.gsub!("</th>\n </tr>", "</th><th><%= t('Force Run') %></th></th>\n </tr>")

# Add the run button
run_button = '<form action="<%= root_path %>loops/<%= loup.lid %>/run" method="post">' \
"<%= csrf_tag %>" \
'<input class="btn btn-danger btn-xs" type="submit" name="run" value="<%= t("Run now") %>" ' \
'data-confirm="Run the job <%= loup.klass %>? <%= t("AreYouSure") %>" />' \
"</form>"

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

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

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

FORCE_RUN_SINGLE_PAGE_ERB
else
match
end
end
end

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

Expand Down
3 changes: 3 additions & 0 deletions lib/sidekiq_belt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "sidekiq/belt"

0 comments on commit ffda7a2

Please sign in to comment.