sidekiq-belt 0.1.0 → 0.2.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: 311732e41366c1a1737b160f74364c13e76015f731191ee0cbd34af81b80afd2
4
+ data.tar.gz: 120418dea454eec7c1c9e47d35ad64d823a478d761accc9b9a6b28505e046e3b
5
5
  SHA512:
6
- metadata.gz: a9ab0684f188afa56b7fe97c1efc88acaf381419c5d1f5f5f879eda5e22c7e7f36e7d48f5e2cf76caede6ae36381cdaf9b5429f89f0a0278269c8f31db71e24a
7
- data.tar.gz: 2b07483a5a2cb6fa6d6a2af9e167857a0da4c5f7b55ee8ccce1e0e225029a71f93d39ebf94a98a39d8727614ea6e0f09445b34e7f62f89c1d27356a710efaa86
6
+ metadata.gz: 32111af8a8f7f4325f4dee59864eb8bcf0469747663dcdab7f0c5bdb5ec7636526f44447e1914b7cd7cce5b3ad60957c66b6fa52ff5fc2ad4549c78c81723ee2
7
+ data.tar.gz: bf61e75d9ca7875ee303726765c323074dfe3f2d76e35ab725cfb51f308a56fbb1fc902a1ce1ae065770ae1e98f88ada773eab0809712ffdb543b9b082146c31
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,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-10-07
4
+
5
+ - Feature to Pause/Unpause Periodic Jobs
6
+
3
7
  ## [0.1.0] - 2023-10-07
4
8
 
5
- - Run manualy Periodic Jobs
9
+ - Feature to run manualy Periodic Jobs
data/README.md CHANGED
@@ -14,10 +14,6 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
 
15
15
  ## Features
16
16
 
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
17
  To enable all features, add the following code to the end of the Sidekiq initializer file:
22
18
 
23
19
  ```ruby
@@ -45,48 +41,28 @@ To enable this feature, pass the `periodic_run` option:
45
41
  Sidekiq::Belt.use!([:periodic_run])
46
42
  ```
47
43
 
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
-
53
- This feature is not yet implemented.
54
-
55
- ### Delete an Unfinished Batch (sidekiq-pro)
56
-
57
- This feature is not yet implemented.
58
- ```
59
- Sidekiq::Belt.use!
60
- ```
44
+ ![periodic_run_index](https://github.com/dannnylo/sidekiq-belt/assets/20794/0cc900bc-6925-4139-affd-f41b81318727)
45
+ ![periodic_run_show](https://github.com/dannnylo/sidekiq-belt/assets/20794/086be190-af8e-44d9-bbf6-eed94b7314a0)
61
46
 
62
- or
63
47
 
64
- ```
65
- Sidekiq::Belt.use!([:all])
66
- ```
48
+ ### Pause Periodic Jobs (sidekiq-enterprise)
67
49
 
68
- To enable only the features you want, add the code to the Sidekiq initializer file while passing the necessary options.
50
+ This option adds a button to pause and unpause the cron of a periodic job.
51
+ When a periodic job is paused, the perform is skiped and on server this content is logged.
69
52
 
70
53
  ```
71
- Sidekiq::Belt.use!([:periodic_run, :periodic_pause])
54
+ 2023-10-12T19:24:00.001Z pid=127183 tid=2ian INFO: Job SomeHourlyWorkerClass is paused by Periodic Pause
72
55
  ```
73
56
 
74
- ### Run manualy Periodic Jobs (sidekiq-enterprise)
57
+ To enable this feature, pass the `periodic_pause` option:
75
58
 
76
- This functionality adds a button on the Sidekiq Enterprise web page that allows manual execution of a job.
77
-
78
- To enable this feature, pass the periodic_run option:
79
-
80
- ```
81
- Sidekiq::Belt.use!([:periodic_run])
59
+ ```ruby
60
+ Sidekiq::Belt.use!([:periodic_pause])
82
61
  ```
83
62
 
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)
63
+ ### Delete an Unfinished Batch (sidekiq-pro)
88
64
 
89
- It will be implemented in upcoming versions.
65
+ This feature is not yet implemented.
90
66
 
91
67
  ### Delete a not finished Batch (sidekiq-pro)
92
68
 
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Belt
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
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.2.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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -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
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'