sidekiq_remove_scheduled 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d902d2dd737af66bc5d66e1fc06411bf2981021
4
+ data.tar.gz: 18a5e8a33ce9ed7328e20b4242a585cc8b8ca984
5
+ SHA512:
6
+ metadata.gz: 9e67b2dae033285fcaf5e73cf7e68ca9f7661a78593674d70e455444c7a1ec262beb95c30c3580e7171a304eacebb46290a75dffa678dad7a383842bb64d9215
7
+ data.tar.gz: ab15dda909d15bfdb9d6700491ba4a76b95faf876846a1c6fe4bd75564cf7e8810629b72afd20c86ac8d11bf296ae7626bcb6cd6b380cbea8afd10949f811f7b
data/Rakefile ADDED
File without changes
@@ -0,0 +1,17 @@
1
+ require 'sidekiq'
2
+ require 'celluloid'
3
+ require 'sidekiq/processor'
4
+ require 'sidekiq_remove_scheduled/job_hook'
5
+ require 'sidekiq_remove_scheduled/process_hook'
6
+
7
+ module Sidekiq
8
+ module Worker
9
+ include SidekiqRemoveScheduled::JobHook
10
+ end
11
+ end
12
+
13
+ module Sidekiq
14
+ class Processor
15
+ include SidekiqRemoveScheduled::ProcessHook
16
+ end
17
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,14 @@
1
+ module SidekiqRemoveScheduled
2
+ module Redis
3
+ class << self
4
+ require 'redis'
5
+ require 'redis-namespace'
6
+ attr_accessor :client, :job_queue
7
+ end
8
+ def self.config(host: nil, port: nil)
9
+ self.client = ::Redis.new(host: host, port: port)
10
+ self.job_queue = ::Redis::Namespace.new(:queue_jobs_map, redis: client)
11
+ self
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'sidekiq_remove_scheduled/redis'
2
+ module SidekiqRemoveScheduled
3
+ def self.bind
4
+ if SidekiqRemoveScheduled::Redis.client.nil?
5
+ SidekiqRemoveScheduled::Redis.config
6
+ end
7
+ require 'sidekiq_remove_scheduled/binder'
8
+ end
9
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module SidekiqRemoveScheduled
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_remove_scheduled
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rohit Jangid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis-namespace
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sidekiq
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: Just call remove_scheduled method and pass the argument to the worker
56
+ to remove scheduled jobs. No need to store Job Ids
57
+ email:
58
+ - rohitjangid@outlook.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Rakefile
64
+ - lib/sidekiq_remove_scheduled.rb
65
+ - lib/sidekiq_remove_scheduled/binder.rb
66
+ - lib/sidekiq_remove_scheduled/job_hook.rb
67
+ - lib/sidekiq_remove_scheduled/process_hook.rb
68
+ - lib/sidekiq_remove_scheduled/redis.rb
69
+ - lib/version.rb
70
+ homepage: https://github.com/rohitjangid/sidekiq_remove_scheduled
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Remove scheduled jobs easily
94
+ test_files: []