resque-disable-job 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3cf5675cd4709d19ab8540335abdf81e3245f658e3ae434a559b82fe097740e7
|
4
|
+
data.tar.gz: d7129819867dc331bda8eec1b61b6409bf2d9c4dac5b85cf6e1eec47dd7c437b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc235c8350945eed9336d2e42c9b58f036259060d3d77782d55838f0386b4c38394c91219fd03e4bc493ba365c75b31c3c04b6c492fb789d0b5368179693c7fb
|
7
|
+
data.tar.gz: 77bbab0994a0c14993fd058c5b32e29cde05c19fea7f83274f13e1278963ede43a58754c0350b84c3d5881a5e11767fde87789f44a98c0c6b7315c23b44e5998
|
@@ -29,9 +29,8 @@ module Resque
|
|
29
29
|
begin
|
30
30
|
# if the rule is not expired
|
31
31
|
if !expired?(specific_rule)
|
32
|
-
# if the arguments received and the ones from the rule
|
33
|
-
|
34
|
-
can_check_rule?(job_name, job_args, specific_rule) ? args_match(job_args, specific_rule.arguments) : false
|
32
|
+
# if the arguments received and the ones from the rule match, that means that we need to disable the current job
|
33
|
+
specific_rule.match?(job_args)
|
35
34
|
else
|
36
35
|
# we remove the rule if it's expired
|
37
36
|
remove_specific_rule(specific_rule)
|
@@ -90,32 +89,8 @@ module Resque
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
# To set the arguments to block we need to keep in mind the parameter order and that
|
94
|
-
# if we don't specify anything, that means we are blocking everything.
|
95
|
-
# The rule is from generic to specific.
|
96
|
-
def self.args_match(args, set_args)
|
97
|
-
return true if args == set_args
|
98
|
-
should_block = args.to_a.map.with_index do |a, i|
|
99
|
-
# We check each parameter (65) or parameters set (["account_id", 65]) in the job_args with the job_args to be blocked
|
100
|
-
# if it's nil, then we match, if it's specified, we check for equality (65 == 65 or ["account_id", 65] == ["account_id", 65])
|
101
|
-
set_args[i].nil? || a == set_args[i]
|
102
|
-
end
|
103
|
-
# if all params are matched [reduce(:&)]
|
104
|
-
should_block.reduce(:&)
|
105
|
-
end
|
106
|
-
|
107
92
|
# Support functions for disabled?
|
108
93
|
|
109
|
-
def self.can_check_rule?(job_name, job_args, rule)
|
110
|
-
if (rule.arguments.is_a?(Array) && job_args.is_a?(Array)) || (rule.arguments.is_a?(Hash) && job_args.is_a?(Hash))
|
111
|
-
true
|
112
|
-
else
|
113
|
-
Resque.logger.error "TYPE MISMATCH while checking disable rule #{rule.digest} (#{rule.serialized_arguments}) for #{job_name}: \
|
114
|
-
job_args is a #{job_args.class} & set_args is a #{rule.arguments.class}"
|
115
|
-
false
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
94
|
def self.get_specific_rule(job_name, set_args, digest)
|
120
95
|
rule = Rule.new(job_name, set_args)
|
121
96
|
Resque.logger.error 'The DIGEST does not match' if rule.digest != digest
|
@@ -133,7 +108,7 @@ module Resque
|
|
133
108
|
Resque.logger.info "Matched running job #{job_name}(#{job_args}) because it was disabled by #{rule}"
|
134
109
|
end
|
135
110
|
|
136
|
-
private_class_method :
|
111
|
+
private_class_method :record_matched_rule, :get_all_rules, :get_specific_rule
|
137
112
|
end
|
138
113
|
end
|
139
114
|
end
|
@@ -57,6 +57,36 @@ module Resque
|
|
57
57
|
def digest
|
58
58
|
@rule_digest ||= Digest::SHA1.hexdigest(serialized_arguments)
|
59
59
|
end
|
60
|
+
|
61
|
+
def match?(args)
|
62
|
+
job_args = normalize_job_args(args)
|
63
|
+
return true if job_args == arguments
|
64
|
+
# We check each parameter in the job_args with the rule arguments to be blocked
|
65
|
+
# if it's nil, then we match as we handle the 'any' case,
|
66
|
+
# if it's specified, we check for equality (65 == 65)
|
67
|
+
should_block = if arguments.is_a?(Hash)
|
68
|
+
job_args.map { |k, v| match_or_nil(k, v) }
|
69
|
+
else
|
70
|
+
job_args.map.with_index { |a, i| match_or_nil(i, a) }
|
71
|
+
end
|
72
|
+
# `!should_block.empty?` handles the edge case of a job with no parameters and the rule args have parameters
|
73
|
+
!should_block.empty? && !should_block.include?(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
def normalize_job_args(job_args)
|
79
|
+
# If the rule arguments is a hash we try to extract the job arguments as a hash to compare apples with apples
|
80
|
+
if arguments.is_a?(Hash)
|
81
|
+
job_args.size == 1 && job_args.first.is_a?(Hash) ? job_args.first : job_args
|
82
|
+
else
|
83
|
+
job_args
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def match_or_nil(key, value)
|
88
|
+
arguments[key].nil? || value == arguments[key]
|
89
|
+
end
|
60
90
|
end
|
61
91
|
end
|
62
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-disable-job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Balcanasu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
195
|
version: '0'
|
196
196
|
requirements: []
|
197
197
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.
|
198
|
+
rubygems_version: 2.7.6
|
199
199
|
signing_key:
|
200
200
|
specification_version: 4
|
201
201
|
summary: Resque plugin that can disable jobs from being processed.
|