sidekiq-belt 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f46a9f9e25f3ca4a020066547c25df3162a9644bd35d7a1a849d5766e0d1eac
4
- data.tar.gz: 7e4153736d66d52c7f86f0721ef4239ee5a7ed51e4b4c51b41a7db2ff6e23c7d
3
+ metadata.gz: 7e20fc5c538638c6ec3efcc44f96a75e8a6a3a15906738e78990add18f15ff5a
4
+ data.tar.gz: e21c25aad43211fa210785d92c7d1e182efbec71471feb7aa48d1cc5dd802cad
5
5
  SHA512:
6
- metadata.gz: a9ab0684f188afa56b7fe97c1efc88acaf381419c5d1f5f5f879eda5e22c7e7f36e7d48f5e2cf76caede6ae36381cdaf9b5429f89f0a0278269c8f31db71e24a
7
- data.tar.gz: 2b07483a5a2cb6fa6d6a2af9e167857a0da4c5f7b55ee8ccce1e0e225029a71f93d39ebf94a98a39d8727614ea6e0f09445b34e7f62f89c1d27356a710efaa86
6
+ metadata.gz: 857d47d6d0dfbe7ffb7b2e97049c5a718877525212508afa787c506aa5497a4ac172a92bf9ee9218673f83bad99efbb076f7460a3b71d63cf2f9431bd34dfb2b
7
+ data.tar.gz: e14112f7c11dde264d54a5143e4d555a54206528effd0c7ae0679ef5106026b942e4e17b3d539214594b8c00e03317acd74f4514f106a526b967f17f635ee1b9
data/.rubocop.yml CHANGED
@@ -1,5 +1,3 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  require:
4
2
  - rubocop-rake
5
3
  - rubocop-rspec
@@ -225,3 +223,19 @@ RSpec/ExampleLength:
225
223
 
226
224
  RSpec/NestedGroups:
227
225
  Enabled: false
226
+
227
+ Metrics/AbcSize:
228
+ Enabled: false
229
+
230
+ Naming/MethodParameterName:
231
+ Enabled: false
232
+
233
+ Naming/FileName:
234
+ Exclude:
235
+ - 'lib/sidekiq-belt.rb'
236
+
237
+ RSpec/VerifiedDoubles:
238
+ Enabled: false
239
+
240
+ RSpec/MultipleMemoizedHelpers:
241
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-10-07
4
+
5
+ - Feature to add button to remove failed batches
6
+
7
+ ## [0.2.0] - 2023-10-07
8
+
9
+ - Feature to Pause/Unpause Periodic Jobs
10
+
3
11
  ## [0.1.0] - 2023-10-07
4
12
 
5
- - Run manualy Periodic Jobs
13
+ - Feature to run manualy Periodic Jobs
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Sidekiq::Belt
2
2
 
3
+
4
+ <a href='http://badge.fury.io/rb/sidekiq-belt'>
5
+ <img src="https://badge.fury.io/rb/sidekiq-belt.png" alt="Gem Version" />
6
+ </a>
7
+ <a href='https://github.com/dannnylo/sidekiq-belt/workflows/CI/badge.svg'>
8
+ <img src="https://github.com/dannnylo/sidekiq-belt/workflows/CI/badge.svg" alt="Build Status" />
9
+ </a>
10
+
3
11
  This Ruby gem enhances the capabilities of Sidekiq, Sidekiq Pro, and Sidekiq Enterprise by adding essential utilities.
4
12
 
5
13
  ## Installation
@@ -14,10 +22,6 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
22
 
15
23
  ## Features
16
24
 
17
- GitHub Copilot: Sure, here's a rewritten version of the content that is easier to read for a developer:
18
-
19
- ## Features
20
-
21
25
  To enable all features, add the following code to the end of the Sidekiq initializer file:
22
26
 
23
27
  ```ruby
@@ -45,52 +49,37 @@ To enable this feature, pass the `periodic_run` option:
45
49
  Sidekiq::Belt.use!([:periodic_run])
46
50
  ```
47
51
 
48
- ![periodic_run_index](https://github.com/dannnylo/sidekiq-belt/assets/20794/1c6ceed7-c2be-447e-b61c-b1e15f002bc2)
49
- ![periodic_run_show](https://github.com/dannnylo/sidekiq-belt/assets/20794/be8cab4b-bfb1-4e15-b01b-56c69231169b)
50
-
51
- ### Pause Periodic Jobs (sidekiq-enterprise)
52
+ ![periodic_run_index](https://github.com/dannnylo/sidekiq-belt/assets/20794/0cc900bc-6925-4139-affd-f41b81318727)
53
+ ![periodic_run_show](https://github.com/dannnylo/sidekiq-belt/assets/20794/086be190-af8e-44d9-bbf6-eed94b7314a0)
52
54
 
53
- This feature is not yet implemented.
54
55
 
55
- ### Delete an Unfinished Batch (sidekiq-pro)
56
-
57
- This feature is not yet implemented.
58
- ```
59
- Sidekiq::Belt.use!
60
- ```
56
+ ### Pause Periodic Jobs (sidekiq-enterprise)
61
57
 
62
- or
58
+ This option adds a button to pause and unpause the cron of a periodic job.
59
+ When a periodic job is paused, the perform is skiped and on server this content is logged.
63
60
 
64
61
  ```
65
- Sidekiq::Belt.use!([:all])
62
+ 2023-10-12T19:24:00.001Z pid=127183 tid=2ian INFO: Job SomeHourlyWorkerClass is paused by Periodic Pause
66
63
  ```
67
64
 
68
- To enable only the features you want, add the code to the Sidekiq initializer file while passing the necessary options.
65
+ To enable this feature, pass the `periodic_pause` option:
69
66
 
67
+ ```ruby
68
+ Sidekiq::Belt.use!([:periodic_pause])
70
69
  ```
71
- Sidekiq::Belt.use!([:periodic_run, :periodic_pause])
72
- ```
73
-
74
- ### Run manualy Periodic Jobs (sidekiq-enterprise)
70
+ ![periodic_pause](https://github.com/dannnylo/sidekiq-belt/assets/20794/41fbcee4-9c5b-45cd-b6f7-c359a22f3979)
71
+ ![periodic_unpause](https://github.com/dannnylo/sidekiq-belt/assets/20794/ea06ae37-068e-4f66-ab10-d83970545a59)
75
72
 
76
- This functionality adds a button on the Sidekiq Enterprise web page that allows manual execution of a job.
73
+ ### Delete an Unfinished Batch (sidekiq-pro)
77
74
 
78
- To enable this feature, pass the periodic_run option:
75
+ This option adds a button to remove failed batches.
79
76
 
77
+ To enable this feature, pass the `failed_batch_remove` option:
78
+ ```ruby
79
+ Sidekiq::Belt.use!([:failed_batch_remove])
80
80
  ```
81
- Sidekiq::Belt.use!([:periodic_run])
82
- ```
83
-
84
- ![periodic_run_index](https://github.com/dannnylo/sidekiq-belt/assets/20794/1c6ceed7-c2be-447e-b61c-b1e15f002bc2)
85
- ![periodic_run_show](https://github.com/dannnylo/sidekiq-belt/assets/20794/be8cab4b-bfb1-4e15-b01b-56c69231169b)
86
-
87
- ### Pause Periodic Jobs (sidekiq-enterprise)
88
-
89
- It will be implemented in upcoming versions.
90
-
91
- ### Delete a not finished Batch (sidekiq-pro)
81
+ ![failed_batch_remove](https://github.com/dannnylo/sidekiq-belt/assets/20794/e285a8b2-4626-48e1-b04a-5190ae51d43b)
92
82
 
93
- It will be implemented in upcoming versions.
94
83
 
95
84
  ## Development
96
85
 
@@ -10,6 +10,8 @@ module Sidekiq
10
10
  def self.use!(_options = [:all])
11
11
  # all = options.include?(:all)
12
12
  # Sidekiq::Belt::Pro::Feature.load! if all || options.include?(:feature)
13
+
14
+ true
13
15
  end
14
16
  end
15
17
  end
@@ -16,6 +16,8 @@ module Sidekiq
16
16
 
17
17
  Sidekiq::Belt::Ent::PeriodicPause.use! if all || options.include?(:periodic_pause)
18
18
  Sidekiq::Belt::Ent::PeriodicRun.use! if all || options.include?(:periodic_run)
19
+
20
+ true
19
21
  end
20
22
  end
21
23
  end
@@ -1,15 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "sidekiq/web/helpers"
4
+
3
5
  module Sidekiq
4
6
  module Belt
5
7
  module Ent
6
8
  module PeriodicPause
9
+ def paused?
10
+ Sidekiq.redis { |r| r.hget("PeriodicPaused", @lid.to_s) }.to_s == "p"
11
+ end
12
+
13
+ def pause!
14
+ Sidekiq.redis { |r| r.hset("PeriodicPaused", @lid.to_s, "p") }
15
+ end
16
+
17
+ def unpause!
18
+ Sidekiq.redis { |r| r.hdel("PeriodicPaused", @lid.to_s) }
19
+ end
20
+
21
+ module SidekiqLoopsPeriodicPause
22
+ PAUSE_BUTTON = <<~ERB
23
+ <form action="<%= root_path %>loops/<%= loup.lid %>/pause" method="post">
24
+ <%= csrf_tag %>
25
+ <input class="btn btn-danger" type="submit" name="pause" value="<%= t('Pause') %>"
26
+ data-confirm="Pause the job <%= loup.klass %>? <%= t('AreYouSure') %>" />
27
+ </form>
28
+ ERB
29
+
30
+ UNPAUSE_BUTTON = <<~ERB
31
+ <form action="<%= root_path %>loops/<%= loup.lid %>/unpause" method="post">
32
+ <%= csrf_tag %>
33
+ <input class="btn btn-danger" type="submit" name="pause" value="<%= t('Unpause') %>"
34
+ data-confirm="Unpause the job <%= loup.klass %>? <%= t('AreYouSure') %>" />
35
+ </form>
36
+ ERB
37
+
38
+ def self.registered(app)
39
+ app.replace_content("/loops") do |content|
40
+ # Add the top of the table
41
+ content.gsub!("</th>\n </tr>", "</th><th><%= t('Pause/Unpause') %></th></th>\n </tr>")
42
+
43
+ # Add the run button
44
+ content.gsub!(
45
+ "</td>\n </tr>\n <% end %>",
46
+ "</td>\n<td>" \
47
+ "<% if (loup.paused?) %>#{UNPAUSE_BUTTON}<% else %>#{PAUSE_BUTTON}<% end %>" \
48
+ "</td>\n </tr>\n <% end %>"
49
+ )
50
+ end
51
+
52
+ app.post("/loops/:lid/pause") do
53
+ Sidekiq::Periodic::Loop.new(params[:lid]).pause!
54
+
55
+ return redirect "#{root_path}loops"
56
+ end
57
+
58
+ app.post("/loops/:lid/unpause") do
59
+ Sidekiq::Periodic::Loop.new(params[:lid]).unpause!
60
+
61
+ return redirect "#{root_path}loops"
62
+ end
63
+ end
64
+ end
65
+
66
+ module PauseServer
67
+ def enqueue_job(cycle, ts)
68
+ cycle.paused? ? logger.info("Job #{cycle.klass} is paused by Periodic Pause") : super
69
+ end
70
+ end
71
+
7
72
  def self.use!
8
- # require("sidekiq-ent/periodic")
9
- # require("sidekiq-ent/periodic/static_loop")
73
+ require("sidekiq-ent/web")
74
+ require("sidekiq-ent/periodic")
75
+ require("sidekiq-ent/periodic/manager")
76
+ require("sidekiq-ent/periodic/static_loop")
10
77
 
11
- # Sidekiq::Periodic::Loop.prepend(Sidekiq::Belt::Ent::PeriodicPause)
12
- # Sidekiq::Periodic::StaticLoop.prepend(Sidekiq::Belt::Ent::PeriodicPause)
78
+ Sidekiq::Web.register(Sidekiq::Belt::Ent::PeriodicPause::SidekiqLoopsPeriodicPause)
79
+ Sidekiq::Periodic::Loop.prepend(Sidekiq::Belt::Ent::PeriodicPause)
80
+ Sidekiq::Periodic::StaticLoop.prepend(Sidekiq::Belt::Ent::PeriodicPause)
81
+ Sidekiq::Periodic::Manager.prepend(Sidekiq::Belt::Ent::PeriodicPause::PauseServer)
13
82
  end
14
83
  end
15
84
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq/web/helpers"
4
+
5
+ module Sidekiq
6
+ module Belt
7
+ module Pro
8
+ module FailedBatchRemove
9
+ module SidekiqFailedBatchRemove
10
+ REMOVE_BUTTON = <<~ERB
11
+ <form action="<%= root_path %>batches/<%= bid %>/remove" method="post">
12
+ <%= csrf_tag %>
13
+ <input class="btn btn-danger" type="submit" name="remove" value="<%= t('Remove') %>"
14
+ data-confirm="Do you want to remove batch <%= bid %>? <%= t('AreYouSure') %>" />
15
+ </form>
16
+ ERB
17
+
18
+ def self.registered(app)
19
+ app.replace_content("/batches") do |content|
20
+ content.gsub!("</th>\n <%", "</th><th><%= t('Delete') %></th>\n <%")
21
+
22
+ content.gsub!(
23
+ "</td>\n </tr>\n <% end %>",
24
+ "</td>\n<td>#{REMOVE_BUTTON}</td>\n </tr>\n <% end %>"
25
+ )
26
+ end
27
+
28
+ app.post("/batches/:bid/remove") do
29
+ Sidekiq::Batch::Status.new(params[:bid]).delete
30
+
31
+ return redirect "#{root_path}batches"
32
+ end
33
+ end
34
+ end
35
+
36
+ def self.use!
37
+ require("sidekiq/web")
38
+
39
+ Sidekiq::Web.register(Sidekiq::Belt::Pro::FailedBatchRemove::SidekiqFailedBatchRemove)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,18 +2,20 @@
2
2
 
3
3
  require "sidekiq"
4
4
 
5
- # require_relative "feature"
5
+ require_relative "failed_batch_remove"
6
6
 
7
7
  module Sidekiq
8
8
  module Belt
9
9
  module Pro
10
10
  module Files
11
- def self.use!(_options = [:all])
11
+ def self.use!(options = [:all])
12
12
  return unless Sidekiq.pro?
13
13
 
14
+ all = options.include?(:all)
15
+
16
+ Sidekiq::Belt::Pro::FailedBatchRemove.use! if all || options.include?(:failed_batch_remove)
17
+
14
18
  true
15
- # all = options.include?(:all)
16
- # Sidekiq::Belt::Pro::Feature.load! if all || options.include?(:feature)
17
19
  end
18
20
  end
19
21
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Belt
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -5,10 +5,6 @@ require "sidekiq/web/action"
5
5
 
6
6
  module Sidekiq
7
7
  module WebActionHelper
8
- def self.blocks
9
- @blocks ||= {}
10
- end
11
-
12
8
  def render(engine, content, options = {})
13
9
  begin
14
10
  path_info = /"([^"]*)"/.match(block.source.to_s)[1]
@@ -18,7 +14,7 @@ module Sidekiq
18
14
 
19
15
  path_info ||= ::Rack::Utils.unescape(env["PATH_INFO"])
20
16
 
21
- Sidekiq::WebActionHelper.blocks.fetch(path_info.to_s, []).each do |content_block|
17
+ Sidekiq::Config::DEFAULTS[:replace_views].fetch(path_info.to_s, []).each do |content_block|
22
18
  content_block.call(content)
23
19
  end
24
20
 
@@ -7,8 +7,9 @@ require_relative "web_action_helper"
7
7
  module Sidekiq
8
8
  module WebRouterHelper
9
9
  def replace_content(path, &block)
10
- Sidekiq::WebActionHelper.blocks[path.to_s] ||= []
11
- Sidekiq::WebActionHelper.blocks[path.to_s] << block
10
+ Sidekiq::Config::DEFAULTS[:replace_views] ||= {}
11
+ Sidekiq::Config::DEFAULTS[:replace_views][path.to_s] ||= []
12
+ Sidekiq::Config::DEFAULTS[:replace_views][path.to_s] << block
12
13
  end
13
14
  end
14
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Jeremias da Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.0'
19
+ version: 7.1.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.0'
26
+ version: 7.1.4
27
27
  description: This Ruby gem enhances the capabilities of Sidekiq, Sidekiq Pro, and
28
28
  Sidekiq Enterprise by adding essential utilities.
29
29
  email:
@@ -34,7 +34,6 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - ".rspec"
36
36
  - ".rubocop.yml"
37
- - ".rubocop_todo.yml"
38
37
  - CHANGELOG.md
39
38
  - CODE_OF_CONDUCT.md
40
39
  - LICENSE
@@ -46,6 +45,7 @@ files:
46
45
  - lib/sidekiq/belt/ent/files.rb
47
46
  - lib/sidekiq/belt/ent/periodic_pause.rb
48
47
  - lib/sidekiq/belt/ent/periodic_run.rb
48
+ - lib/sidekiq/belt/pro/failed_batch_remove.rb
49
49
  - lib/sidekiq/belt/pro/files.rb
50
50
  - lib/sidekiq/belt/version.rb
51
51
  - lib/sidekiq/web_action_helper.rb
data/.rubocop_todo.yml DELETED
@@ -1,15 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2023-10-11 15:02:29 UTC using RuboCop version 1.56.4.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
11
- # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
12
- # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
13
- Naming/FileName:
14
- Exclude:
15
- - 'lib/sidekiq-belt.rb'