subserver 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subserver/listener.rb +5 -42
- data/lib/subserver/middleware/active_record.rb +1 -1
- data/lib/subserver/pubsub.rb +1 -1
- data/lib/subserver/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 391f8405b0cd22e8f4aa640004133d2d73f52937
|
4
|
+
data.tar.gz: ed7f18529bd0c0d5aa297fc8bb9b0cc5ac271de5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb3386a5cb879d6905caed2f65789a77ce7c3c673861bf0277563bea6b34204a7f4ce0803c14f4f44255a48dc0ccad2d4f9ffe475ac56e764cf45883ae3843a
|
7
|
+
data.tar.gz: ce1bfe6ba1fa69aeb424051c0932f019cd9284b885d36d76c5e25dc7fbf6b8d6c587d7f061bde9a715e28f210dbaa82a7bf3f16d62cd40fe3744a079268e38b4
|
data/lib/subserver/listener.rb
CHANGED
@@ -102,8 +102,10 @@ module Subserver
|
|
102
102
|
def process_message(received_message)
|
103
103
|
begin
|
104
104
|
logger.debug("Executing Middleware")
|
105
|
-
|
106
|
-
|
105
|
+
@reloader.call do
|
106
|
+
Subserver.middleware.invoke(@subscriber, received_message) do
|
107
|
+
execute(@subscriber, received_message)
|
108
|
+
end
|
107
109
|
end
|
108
110
|
rescue Subserver::Shutdown
|
109
111
|
# Reject message if shutdown
|
@@ -114,48 +116,9 @@ module Subserver
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
|
-
def
|
119
|
+
def execute(subscriber, received_message)
|
118
120
|
subscriber.new.perform(received_message)
|
119
121
|
end
|
120
122
|
|
121
|
-
# Ruby doesn't provide atomic counters out of the box so we'll
|
122
|
-
# implement something simple ourselves.
|
123
|
-
# https://bugs.ruby-lang.org/issues/14706
|
124
|
-
class Counter
|
125
|
-
def initialize
|
126
|
-
@value = 0
|
127
|
-
@lock = Mutex.new
|
128
|
-
end
|
129
|
-
|
130
|
-
def incr(amount=1)
|
131
|
-
@lock.synchronize { @value = @value + amount }
|
132
|
-
end
|
133
|
-
|
134
|
-
def reset
|
135
|
-
@lock.synchronize { val = @value; @value = 0; val }
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
PROCESSED = Counter.new
|
140
|
-
FAILURE = Counter.new
|
141
|
-
# This is mutable global state but because each thread is storing
|
142
|
-
# its own unique key/value, there's no thread-safety issue AFAIK.
|
143
|
-
WORKER_STATE = {}
|
144
|
-
|
145
|
-
def stats(job_hash, queue)
|
146
|
-
tid = Subserver::Logging.tid
|
147
|
-
WORKER_STATE[tid] = {:queue => queue, :payload => job_hash, :run_at => Time.now.to_i }
|
148
|
-
|
149
|
-
begin
|
150
|
-
yield
|
151
|
-
rescue Exception
|
152
|
-
FAILURE.incr
|
153
|
-
raise
|
154
|
-
ensure
|
155
|
-
WORKER_STATE.delete(tid)
|
156
|
-
PROCESSED.incr
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
123
|
end
|
161
124
|
end
|
data/lib/subserver/pubsub.rb
CHANGED
@@ -8,7 +8,7 @@ module Subserver
|
|
8
8
|
|
9
9
|
def self.initialize_client
|
10
10
|
@client = Google::Cloud::Pubsub.new(
|
11
|
-
project_id: options[:project_id],
|
11
|
+
project_id: options[:project_id] || ENV['PUBSUB_PROJECT_ID'],
|
12
12
|
credentials: ( File.expand_path(options[:credentials]) if options[:credentials] )
|
13
13
|
)
|
14
14
|
end
|
data/lib/subserver/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Hill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-pubsub
|