sidekiq_remove_scheduled 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq_remove_scheduled/binder.rb +5 -4
- data/lib/sidekiq_remove_scheduled/hooks/job_hook.rb +44 -0
- data/lib/sidekiq_remove_scheduled/hooks/process_hook.rb +24 -0
- data/lib/sidekiq_remove_scheduled/logger.rb +15 -0
- data/lib/version.rb +1 -1
- metadata +4 -3
- data/lib/sidekiq_remove_scheduled/job_hook.rb +0 -40
- data/lib/sidekiq_remove_scheduled/process_hook.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 031d06e38a793a86fbc0b4a761d886b3f5a60fa4
|
4
|
+
data.tar.gz: 31b4bef861a03adf69277d85b4cfb8ccd248dffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a2024dde2eacca190749ec00c613404b33d14b6c44693c6a4dc456be8129e94e3a9d32ab6dfbb2fa539bff5873ebc3ab40886b4c39c0845440da40aa5fa8fd
|
7
|
+
data.tar.gz: ae24b76b63013f26d8a06fffa4fc132b31f361f2ca5eaa336bc1688ce386b8e86f6269ef4f3e677e9c898990a1c54c6a1ad707448d82b3e6700486650ebff1d0
|
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'sidekiq'
|
2
2
|
require 'celluloid'
|
3
3
|
require 'sidekiq/processor'
|
4
|
-
require 'sidekiq_remove_scheduled/
|
5
|
-
require 'sidekiq_remove_scheduled/
|
4
|
+
require 'sidekiq_remove_scheduled/logger'
|
5
|
+
require 'sidekiq_remove_scheduled/hooks/job_hook'
|
6
|
+
require 'sidekiq_remove_scheduled/hooks/process_hook'
|
6
7
|
|
7
8
|
module Sidekiq
|
8
9
|
module Worker
|
9
|
-
include SidekiqRemoveScheduled::JobHook
|
10
|
+
include SidekiqRemoveScheduled::Hooks::JobHook
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
module Sidekiq
|
14
15
|
class Processor
|
15
|
-
include SidekiqRemoveScheduled::ProcessHook
|
16
|
+
include SidekiqRemoveScheduled::Hooks::ProcessHook
|
16
17
|
end
|
17
18
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SidekiqRemoveScheduled
|
2
|
+
module Hooks
|
3
|
+
module JobHook
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
module ClassMethods
|
8
|
+
def self.extended(base)
|
9
|
+
perform_in_hook base
|
10
|
+
remove_scheduled_jobs base
|
11
|
+
end
|
12
|
+
def self.perform_in_hook(base)
|
13
|
+
default_perform_in = base::ClassMethods.instance_method(:perform_in)
|
14
|
+
base::ClassMethods.send :define_method, :perform_in do |interval, *args|
|
15
|
+
jid = default_perform_in.bind(self).call(interval, *args)
|
16
|
+
field = "#{self.to_s}-#{args.to_s}"
|
17
|
+
::SidekiqRemoveScheduled::Logger.log("Storing job id: #{jid} for field: #{field}")
|
18
|
+
jobs = ::SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
19
|
+
jobs << jid
|
20
|
+
::SidekiqRemoveScheduled::Redis.job_queue.set(field, jobs.uniq.join(','))
|
21
|
+
end
|
22
|
+
base::ClassMethods.send :alias_method, :perform_at, :perform_in
|
23
|
+
end
|
24
|
+
def self.remove_scheduled_jobs(base)
|
25
|
+
base::ClassMethods.send :define_method, :remove_scheduled do |*args|
|
26
|
+
field = "#{self.to_s}-#{args.to_s}"
|
27
|
+
::SidekiqRemoveScheduled::Logger.log("Removing scheduled jobs for field: #{field}")
|
28
|
+
jobs = ::SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
29
|
+
jobs.each do |job_id|
|
30
|
+
pattern = '*,\"jid\":\"'+job_id+'\",*'
|
31
|
+
itterator = 0
|
32
|
+
begin
|
33
|
+
job = ::SidekiqRemoveScheduled::Redis.client.zscan('schedule', itterator, match: pattern)
|
34
|
+
itterator = job.first.to_i
|
35
|
+
end until job.last.present? || itterator == 0
|
36
|
+
::SidekiqRemoveScheduled::Redis.client.zrem('schedule', job.last.first) if job.last.present?
|
37
|
+
end
|
38
|
+
::SidekiqRemoveScheduled::Redis.job_queue.del(field)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SidekiqRemoveScheduled
|
2
|
+
module Hooks
|
3
|
+
module ProcessHook
|
4
|
+
def self.included(base)
|
5
|
+
execute_job_hook base
|
6
|
+
end
|
7
|
+
def self.execute_job_hook(base)
|
8
|
+
default_execute_job = base.instance_method(:execute_job)
|
9
|
+
base.send :define_method, :execute_job do |worker, args|
|
10
|
+
default_execute_job.bind(self).call(worker, args)
|
11
|
+
field = "#{worker.class.to_s}-#{args.to_s}"
|
12
|
+
::SidekiqRemoveScheduled::Logger.log("Processing and removing job id: #{worker.jid} for field: #{field}")
|
13
|
+
jobs = ::SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
14
|
+
jobs.delete(worker.jid)
|
15
|
+
if jobs.blank?
|
16
|
+
::SidekiqRemoveScheduled::Redis.job_queue.del(field)
|
17
|
+
else
|
18
|
+
::SidekiqRemoveScheduled::Redis.job_queue.set(field, jobs.join(','))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_remove_scheduled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rohit Jangid
|
@@ -63,8 +63,9 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- lib/sidekiq_remove_scheduled.rb
|
65
65
|
- lib/sidekiq_remove_scheduled/binder.rb
|
66
|
-
- lib/sidekiq_remove_scheduled/job_hook.rb
|
67
|
-
- lib/sidekiq_remove_scheduled/process_hook.rb
|
66
|
+
- lib/sidekiq_remove_scheduled/hooks/job_hook.rb
|
67
|
+
- lib/sidekiq_remove_scheduled/hooks/process_hook.rb
|
68
|
+
- lib/sidekiq_remove_scheduled/logger.rb
|
68
69
|
- lib/sidekiq_remove_scheduled/redis.rb
|
69
70
|
- lib/version.rb
|
70
71
|
homepage: https://github.com/rohitjangid/sidekiq_remove_scheduled
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module SidekiqRemoveScheduled
|
2
|
-
module JobHook
|
3
|
-
def self.included(base)
|
4
|
-
base.extend ClassMethods
|
5
|
-
end
|
6
|
-
module ClassMethods
|
7
|
-
def self.extended(base)
|
8
|
-
perform_in_hook base
|
9
|
-
remove_scheduled_jobs base
|
10
|
-
end
|
11
|
-
def self.perform_in_hook(base)
|
12
|
-
default_perform_in = base::ClassMethods.instance_method(:perform_in)
|
13
|
-
base::ClassMethods.send :define_method, :perform_in do |interval, *args|
|
14
|
-
jid = default_perform_in.bind(self).call(interval, *args)
|
15
|
-
field = "#{self.to_s}-#{args.to_s}"
|
16
|
-
jobs = SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
17
|
-
jobs << jid
|
18
|
-
SidekiqRemoveScheduled::Redis.job_queue.set(field, jobs.uniq.join(','))
|
19
|
-
end
|
20
|
-
base::ClassMethods.send :alias_method, :perform_at, :perform_in
|
21
|
-
end
|
22
|
-
def self.remove_scheduled_jobs(base)
|
23
|
-
base::ClassMethods.send :define_method, :remove_scheduled do |*args|
|
24
|
-
field = "#{self.to_s}-#{args.to_s}"
|
25
|
-
jobs = SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
26
|
-
jobs.each do |job_id|
|
27
|
-
pattern = '*,\"jid\":\"'+job_id+'\",*'
|
28
|
-
itterator = 0
|
29
|
-
begin
|
30
|
-
job = SidekiqRemoveScheduled::Redis.client.zscan('schedule', itterator, match: pattern)
|
31
|
-
itterator = job.first.to_i
|
32
|
-
end until job.last.present? || itterator == 0
|
33
|
-
SidekiqRemoveScheduled::Redis.client.zrem('schedule', job.last.first) if job.last.present?
|
34
|
-
end
|
35
|
-
SidekiqRemoveScheduled::Redis.job_queue.del(field)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module SidekiqRemoveScheduled
|
2
|
-
module ProcessHook
|
3
|
-
def self.included(base)
|
4
|
-
execute_job_hook base
|
5
|
-
end
|
6
|
-
def self.execute_job_hook(base)
|
7
|
-
default_execute_job = base.instance_method(:execute_job)
|
8
|
-
base.send :define_method, :execute_job do |worker, args|
|
9
|
-
default_execute_job.bind(self).call(worker, args)
|
10
|
-
field = "#{worker.class.to_s}-#{args.to_s}"
|
11
|
-
jobs = SidekiqRemoveScheduled::Redis.job_queue.get(field).to_s.split(',')
|
12
|
-
jobs.delete(worker.jid)
|
13
|
-
if jobs.blank?
|
14
|
-
SidekiqRemoveScheduled::Redis.job_queue.del(field)
|
15
|
-
else
|
16
|
-
SidekiqRemoveScheduled::Redis.job_queue.set(field, jobs.join(','))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|