zuora_connect 1.4.59 → 1.4.60
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 +4 -4
- data/app/models/zuora_connect/app_instance_base.rb +17 -0
- data/config/initializers/resque.rb +5 -0
- data/lib/resque/additions.rb +53 -0
- data/lib/resque/dynamic_queues.rb +73 -0
- data/lib/resque/self_lookup.rb +12 -0
- data/lib/zuora_connect.rb +3 -0
- data/lib/zuora_connect/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d2b7673aeef42a11c627db572865c7c0eb5001c6
|
|
4
|
+
data.tar.gz: 83a08a7e946ba4aebf6a7a0e734bdf3a5032b81c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fefb2bb88a4acb786ab92393f96886411aaa8e377f44eeff7e6c45f0da7699f714c1cbdbb7057120098497f73be9c2bf2725000289b601a46fc9c6e3d4562a19
|
|
7
|
+
data.tar.gz: 88fa4fa9f39d6ee3f380ee293018c5d8c8ce7cf0eb0195f7fa8ed11ff5ec8ac383aed10a752d8f1fe5612a817538d610b863ddd4c8bf830d1e684fb44e249df0
|
|
@@ -82,6 +82,23 @@ module ZuoraConnect
|
|
|
82
82
|
return ActiveSupport::MessageEncryptor.new(secret, sign_secret)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
def api_limit(start: true, time: 2.minutes.to_i)
|
|
86
|
+
if start
|
|
87
|
+
Redis.current.set("APILimits:#{self.id}", true)
|
|
88
|
+
Redis.current.expire("APILimits:#{self.id}", time)
|
|
89
|
+
else
|
|
90
|
+
Redis.current.del("APILimits:#{self.id}")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def queue_pause
|
|
95
|
+
Redis.current.set("resque:PauseQueue:#{self.id}", true)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def queue_start
|
|
99
|
+
Redis.current.del("resque:PauseQueue:#{self.id}")
|
|
100
|
+
end
|
|
101
|
+
|
|
85
102
|
def catalog_outdated?(time: Time.now - 12.hours)
|
|
86
103
|
return self.catalog_updated_at.blank? || (self.catalog_updated_at < time)
|
|
87
104
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Resque
|
|
2
|
+
module Additions
|
|
3
|
+
def dequeue_from(queue, klass, *args)
|
|
4
|
+
####### ------ Resque Job --------
|
|
5
|
+
# Perform before_dequeue hooks. Don't perform dequeue if any hook returns false
|
|
6
|
+
before_hooks = Plugin.before_dequeue_hooks(klass).collect do |hook|
|
|
7
|
+
klass.send(hook, *args)
|
|
8
|
+
end
|
|
9
|
+
return if before_hooks.any? { |result| result == false }
|
|
10
|
+
|
|
11
|
+
destroyed = Job.destroy(queue, klass, *args)
|
|
12
|
+
|
|
13
|
+
Plugin.after_dequeue_hooks(klass).each do |hook|
|
|
14
|
+
klass.send(hook, *args)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
destroyed
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
####### ------ Resque Delayed Job --------
|
|
21
|
+
# Returns delayed jobs schedule timestamp for +klass+, +args+.
|
|
22
|
+
def scheduled_at_with_queue(queue, klass, *args)
|
|
23
|
+
search = encode(job_to_hash_with_queue(queue,klass, args))
|
|
24
|
+
redis.smembers("timestamps:#{search}").map do |key|
|
|
25
|
+
key.tr('delayed:', '').to_i
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Given an encoded item, remove it from the delayed_queue
|
|
30
|
+
def remove_delayed_with_queue(queue, klass, *args)
|
|
31
|
+
search = encode(job_to_hash_with_queue(queue,klass, args))
|
|
32
|
+
remove_delayed_job(search)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#Given a timestamp and job (klass + args) it removes all instances and
|
|
36
|
+
# returns the count of jobs removed.
|
|
37
|
+
#
|
|
38
|
+
# O(N) where N is the number of jobs scheduled to fire at the given
|
|
39
|
+
# timestamp
|
|
40
|
+
def remove_delayed_job_with_queue_from_timestamp(timestamp, queue, klass, *args)
|
|
41
|
+
return 0 if Resque.inline?
|
|
42
|
+
|
|
43
|
+
key = "delayed:#{timestamp.to_i}"
|
|
44
|
+
encoded_job = encode(job_to_hash_with_queue(queue, klass, args))
|
|
45
|
+
|
|
46
|
+
redis.srem("timestamps:#{encoded_job}", key)
|
|
47
|
+
count = redis.lrem(key, 0, encoded_job)
|
|
48
|
+
clean_up_timestamp(key, timestamp)
|
|
49
|
+
|
|
50
|
+
count
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Resque
|
|
2
|
+
module DynamicQueues
|
|
3
|
+
# Returns a list of queues to use when searching for a job.
|
|
4
|
+
#
|
|
5
|
+
# A splat ("*") means you want every queue (in alpha order) - this
|
|
6
|
+
# can be useful for dynamically adding new queues.
|
|
7
|
+
#
|
|
8
|
+
# The splat can also be used as a wildcard within a queue name,
|
|
9
|
+
# e.g. "*high*", and negation can be indicated with a prefix of "!"
|
|
10
|
+
#
|
|
11
|
+
# An @key can be used to dynamically look up the queue list for key from redis.
|
|
12
|
+
# If no key is supplied, it defaults to the worker's hostname, and wildcards
|
|
13
|
+
# and negations can be used inside this dynamic queue list. Set the queue
|
|
14
|
+
# list for a key with Resque.set_dynamic_queue(key, ["q1", "q2"]
|
|
15
|
+
#
|
|
16
|
+
def queues_with_dynamic
|
|
17
|
+
queue_names = @queues.dup
|
|
18
|
+
|
|
19
|
+
return queues_without_dynamic if queue_names.grep(/(^!)|(^@)|(\*)/).size == 0
|
|
20
|
+
|
|
21
|
+
real_queues = Resque.queues
|
|
22
|
+
matched_queues = []
|
|
23
|
+
|
|
24
|
+
#Remove Queues under Api Limits
|
|
25
|
+
api_limit_instances = Redis.current.keys("APILimits:*").map {|key| key.split('APILimits:').last.to_i}
|
|
26
|
+
real_queues = real_queues.select {|key| key if !api_limit_instances.include?((key.match(/^(\d*)_.*/) || [])[1].to_i)}
|
|
27
|
+
|
|
28
|
+
#Queue Pausing
|
|
29
|
+
paused_instances = Redis.current.keys("resque:PauseQueue:*").map {|key| key.split('resque:PauseQueue:').last.to_i}
|
|
30
|
+
real_queues = real_queues.select {|key| key if !paused_instances.include?((key.match(/^(\d*)_.*/) || [])[1].to_i)}
|
|
31
|
+
|
|
32
|
+
while q = queue_names.shift
|
|
33
|
+
q = q.to_s
|
|
34
|
+
|
|
35
|
+
if q =~ /^(!)?@(.*)/
|
|
36
|
+
key = $2.strip
|
|
37
|
+
key = hostname if key.size == 0
|
|
38
|
+
|
|
39
|
+
add_queues = Resque.get_dynamic_queue(key)
|
|
40
|
+
add_queues.map! { |q| q.gsub!(/^!/, '') || q.gsub!(/^/, '!') } if $1
|
|
41
|
+
|
|
42
|
+
queue_names.concat(add_queues)
|
|
43
|
+
next
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if q =~ /^!/
|
|
47
|
+
negated = true
|
|
48
|
+
q = q[1..-1]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
patstr = q.gsub(/\*/, ".*")
|
|
52
|
+
pattern = /^#{patstr}$/
|
|
53
|
+
if negated
|
|
54
|
+
matched_queues -= matched_queues.grep(pattern)
|
|
55
|
+
else
|
|
56
|
+
matches = real_queues.grep(/^#{pattern}$/)
|
|
57
|
+
matches = [q] if matches.size == 0 && q == patstr
|
|
58
|
+
matched_queues.concat(matches.sort)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
return matched_queues.uniq
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def self.included(receiver)
|
|
67
|
+
receiver.class_eval do
|
|
68
|
+
alias queues_without_dynamic queues
|
|
69
|
+
alias queues queues_with_dynamic
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Resque
|
|
2
|
+
module SelfLookup
|
|
3
|
+
def payload_class
|
|
4
|
+
@payload_class ||= constantize(@payload['class'])
|
|
5
|
+
@payload_class.instance_eval { class << self; self end }.send(:attr_accessor, :worker)
|
|
6
|
+
@payload_class.instance_eval { class << self; self end }.send(:attr_accessor, :job)
|
|
7
|
+
@payload_class.worker = self.worker
|
|
8
|
+
@payload_class.job = self
|
|
9
|
+
return @payload_class
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/zuora_connect.rb
CHANGED
|
@@ -4,6 +4,9 @@ require 'zuora_connect/exceptions'
|
|
|
4
4
|
require 'zuora_connect/controllers/helpers'
|
|
5
5
|
require 'zuora_connect/views/helpers'
|
|
6
6
|
require 'zuora_connect/railtie'
|
|
7
|
+
require 'resque/additions'
|
|
8
|
+
require 'resque/dynamic_queues'
|
|
9
|
+
require 'resque/self_lookup'
|
|
7
10
|
|
|
8
11
|
module ZuoraConnect
|
|
9
12
|
class << self
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zuora_connect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.60
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Connect Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-10-
|
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord-session_store
|
|
@@ -225,6 +225,7 @@ files:
|
|
|
225
225
|
- app/views/zuora_connect/static/session_error.html.erb
|
|
226
226
|
- config/initializers/apartment.rb
|
|
227
227
|
- config/initializers/redis.rb
|
|
228
|
+
- config/initializers/resque.rb
|
|
228
229
|
- config/routes.rb
|
|
229
230
|
- db/migrate/20100718151733_create_connect_app_instances.rb
|
|
230
231
|
- db/migrate/20101024162319_add_tokens_to_app_instance.rb
|
|
@@ -235,6 +236,9 @@ files:
|
|
|
235
236
|
- db/migrate/20110503003602_add_catalog_data_to_app_instance.rb
|
|
236
237
|
- db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb
|
|
237
238
|
- db/migrate/20110503003604_catalog_default.rb
|
|
239
|
+
- lib/resque/additions.rb
|
|
240
|
+
- lib/resque/dynamic_queues.rb
|
|
241
|
+
- lib/resque/self_lookup.rb
|
|
238
242
|
- lib/tasks/zuora_connect_tasks.rake
|
|
239
243
|
- lib/zuora_connect.rb
|
|
240
244
|
- lib/zuora_connect/configuration.rb
|