boxxspring-workers 1.1.4 → 1.1.5
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/lib/boxxspring/abstract.rb +4 -0
- data/lib/boxxspring/synchronization/orchestrator.rb +9 -2
- data/lib/boxxspring/synchronization/variable.rb +2 -2
- data/lib/boxxspring/worker/base.rb +92 -59
- data/lib/boxxspring/worker/configuration.rb +23 -18
- data/lib/boxxspring/worker/logging.rb +95 -0
- data/lib/boxxspring/worker/task_base.rb +22 -37
- data/lib/boxxspring/worker.rb +23 -0
- data/lib/boxxspring-worker-version.rb +1 -1
- data/lib/boxxspring-worker.rb +2 -0
- data/lib/tasks/workers.rake +13 -17
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d891511f5e9885528269e401d43946f8eab6e9
|
4
|
+
data.tar.gz: 7c4d7828f39a16ccecc075387792ca63eba21879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6b1079cc3a9b932f4d44ae19b584ea77e414a2929e193e2e4ff3cb1330dca72bd59eff298222aad07456435da083af7b518a286ee3a728ddbd2ca342e0bc9b
|
7
|
+
data.tar.gz: 94ba8c40b9ef4bbb5e2f04074acfefecd3f0376f2d8217fd6966f89ab36a6d6eb03fa3ca74b116bbb4c98baf679868e5cf5e34f8fc65eddff4e1129e19903c9c
|
data/lib/boxxspring/abstract.rb
CHANGED
@@ -27,8 +27,15 @@ module Boxxspring
|
|
27
27
|
true : false
|
28
28
|
end
|
29
29
|
|
30
|
-
def read( key )
|
31
|
-
|
30
|
+
def read( key, options = {} )
|
31
|
+
range = options[ :range ]
|
32
|
+
if range
|
33
|
+
range_start = range[ :start ] || 0
|
34
|
+
range_end = range[ :end ] || -1
|
35
|
+
@provider.lrange( key, range_start, range_end )
|
36
|
+
else
|
37
|
+
@provider.get( key )
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
def write( key, value, options = {} )
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Boxxspring
|
1
|
+
module Boxxspring
|
2
2
|
|
3
3
|
module Worker
|
4
4
|
|
@@ -7,16 +7,22 @@ module Boxxspring
|
|
7
7
|
|
8
8
|
class Base
|
9
9
|
|
10
|
+
#------------------------------------------------------------------------
|
11
|
+
# modules
|
12
|
+
|
13
|
+
include Logging
|
14
|
+
|
10
15
|
#------------------------------------------------------------------------
|
11
16
|
# class attributes
|
12
17
|
|
13
18
|
class_attribute :queue_name
|
14
19
|
class_attribute :processor
|
20
|
+
class_attribute :environment
|
15
21
|
|
16
22
|
#------------------------------------------------------------------------
|
17
23
|
# class methods
|
18
24
|
|
19
|
-
class << self
|
25
|
+
class << self
|
20
26
|
|
21
27
|
public; def process( &block )
|
22
28
|
self.processor = block
|
@@ -27,25 +33,27 @@ module Boxxspring
|
|
27
33
|
end
|
28
34
|
|
29
35
|
def queue_url
|
30
|
-
|
31
|
-
response = self.queue_interface.create_queue(
|
32
|
-
queue_name: self.full_queue_name
|
36
|
+
@queue_url ||= begin
|
37
|
+
response = self.queue_interface.create_queue(
|
38
|
+
queue_name: self.full_queue_name
|
33
39
|
)
|
34
|
-
|
40
|
+
response[ :queue_url ]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def environment
|
45
|
+
@environment ||= begin
|
46
|
+
Worker.env == 'development' ?
|
47
|
+
( ENV[ 'USER' ].underscore || 'development' ) :
|
48
|
+
Worker.env
|
35
49
|
end
|
36
|
-
@queue_url
|
37
50
|
end
|
38
51
|
|
39
52
|
protected; def full_queue_name
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
( self.queue_name ||
|
45
|
-
self.name.
|
46
|
-
underscore.
|
47
|
-
gsub( /[\/]/, '-' ).
|
48
|
-
gsub( /_worker\Z/, '' ) )
|
53
|
+
queue_name = self.queue_name ||
|
54
|
+
self.name.underscore.gsub( /[\/]/, '-' ).
|
55
|
+
gsub( /_worker\Z/, '' )
|
56
|
+
self.environment + '-' + queue_name
|
49
57
|
end
|
50
58
|
|
51
59
|
end
|
@@ -53,11 +61,12 @@ module Boxxspring
|
|
53
61
|
#------------------------------------------------------------------------
|
54
62
|
# operations
|
55
63
|
|
56
|
-
def process
|
57
|
-
messages = self.receive_messages() || []
|
64
|
+
def process
|
65
|
+
messages = self.receive_messages() || []
|
58
66
|
messages.each do | message |
|
59
67
|
if message.present?
|
60
68
|
payload = self.payload_from_message( message )
|
69
|
+
|
61
70
|
if payload.present?
|
62
71
|
begin
|
63
72
|
result = self.process_payload( payload )
|
@@ -65,43 +74,37 @@ module Boxxspring
|
|
65
74
|
self.delete_message( message ) unless result == false
|
66
75
|
rescue StandardError => error
|
67
76
|
self.logger.error(
|
68
|
-
"The #{ self.human_name }
|
69
|
-
"payload. "
|
77
|
+
"The #{ self.human_name } failed to process the payload."
|
70
78
|
)
|
71
79
|
self.logger.error( error.message )
|
72
|
-
self.logger.
|
80
|
+
self.logger.info( error.backtrace.join( "\n" ) )
|
73
81
|
end
|
74
82
|
else
|
75
|
-
# note: messages with invalid payloads are deleted
|
76
83
|
self.delete_message( message )
|
77
84
|
self.logger.error(
|
78
|
-
"The #{ self.human_name }
|
85
|
+
"The #{ self.human_name } received an invalid payload."
|
79
86
|
)
|
80
87
|
end
|
81
88
|
end
|
82
89
|
end
|
83
90
|
end
|
84
91
|
|
85
|
-
protected; def logger
|
86
|
-
@logger ||= Boxxspring::Worker.configuration.logger
|
87
|
-
end
|
88
|
-
|
89
92
|
#------------------------------------------------------------------------
|
90
93
|
# implementation
|
91
94
|
|
92
95
|
protected; def receive_messages
|
93
96
|
messages = nil
|
94
97
|
begin
|
95
|
-
response = self.class.queue_interface.receive_message(
|
98
|
+
response = self.class.queue_interface.receive_message(
|
96
99
|
queue_url: self.class.queue_url,
|
97
100
|
max_number_of_messages: QUEUE_MESSAGE_REQUEST_COUNT,
|
98
|
-
wait_time_seconds: QUEUE_MESSAGE_WAIT_IN_SECONDS
|
101
|
+
wait_time_seconds: QUEUE_MESSAGE_WAIT_IN_SECONDS
|
99
102
|
)
|
100
103
|
messages = response[ :messages ]
|
101
104
|
rescue StandardError => error
|
102
|
-
raise RuntimeError.new(
|
103
|
-
"The #{ self.human_name }
|
104
|
-
"from the queue. #{error.message}."
|
105
|
+
raise RuntimeError.new(
|
106
|
+
"The #{ self.human_name } is unable to receive a message " +
|
107
|
+
"from the queue. #{ error.message }."
|
105
108
|
)
|
106
109
|
end
|
107
110
|
messages
|
@@ -109,54 +112,59 @@ module Boxxspring
|
|
109
112
|
|
110
113
|
protected; def delete_message( message )
|
111
114
|
begin
|
112
|
-
self.class.queue_interface.delete_message(
|
115
|
+
self.class.queue_interface.delete_message(
|
113
116
|
queue_url: self.class.queue_url,
|
114
117
|
receipt_handle: message[ :receipt_handle ]
|
115
118
|
)
|
116
119
|
rescue StandardError => error
|
117
|
-
raise RuntimeError.new(
|
118
|
-
"The #{ self.human_name }
|
119
|
-
"message from the queue. #{error.message}."
|
120
|
+
raise RuntimeError.new(
|
121
|
+
"The #{ self.human_name } is unable to delete the " +
|
122
|
+
"message from the queue. #{ error.message }."
|
120
123
|
)
|
121
124
|
end
|
125
|
+
|
122
126
|
message
|
123
127
|
end
|
124
128
|
|
125
129
|
protected; def payload_from_message( message )
|
130
|
+
|
126
131
|
payload = message.body
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
+
|
133
|
+
if payload.present?
|
134
|
+
payload = JSON.parse( payload ) rescue payload
|
135
|
+
if payload.is_a?( Hash ) && payload.include?( 'Type' ) &&
|
136
|
+
payload[ 'Type' ] == 'Notification'
|
132
137
|
payload = payload[ 'Message' ]
|
133
|
-
payload = payload.present? ?
|
134
|
-
( JSON.parse( payload ) rescue payload ) :
|
138
|
+
payload = payload.present? ?
|
139
|
+
( JSON.parse( payload ) rescue payload ) :
|
135
140
|
payload
|
136
|
-
end
|
141
|
+
end
|
142
|
+
else
|
143
|
+
logger.error( "The message lacks a payload." )
|
144
|
+
logger.debug( message.inspect )
|
137
145
|
end
|
138
146
|
payload
|
139
147
|
end
|
140
148
|
|
141
149
|
protected; def process_payload( payload )
|
142
|
-
if self.class.processor.present?
|
150
|
+
if self.class.processor.present?
|
143
151
|
self.class.processor.call( payload )
|
144
152
|
else
|
145
|
-
raise RuntimeError.new(
|
153
|
+
raise RuntimeError.new(
|
146
154
|
"The worker lacks a processor"
|
147
155
|
)
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
151
159
|
protected; def delegate_payload( queue_name, payload )
|
152
|
-
|
153
|
-
|
154
|
-
queue_name = queue_name_prefix + '-' + queue_name
|
160
|
+
queue_name = self.class.environment + '-' + queue_name
|
161
|
+
|
155
162
|
begin
|
156
|
-
response = self.class.queue_interface.create_queue(
|
157
|
-
queue_name: queue_name
|
163
|
+
response = self.class.queue_interface.create_queue(
|
164
|
+
queue_name: queue_name
|
158
165
|
)
|
159
|
-
queue_url = response[ :queue_url ]
|
166
|
+
queue_url = response[ :queue_url ]
|
167
|
+
|
160
168
|
if queue_url.present?
|
161
169
|
self.class.queue_interface.send_message(
|
162
170
|
queue_url: queue_url,
|
@@ -164,18 +172,43 @@ module Boxxspring
|
|
164
172
|
)
|
165
173
|
end
|
166
174
|
rescue StandardError => error
|
167
|
-
raise RuntimeError.new(
|
168
|
-
"The #{ self.human_name }
|
169
|
-
"payload to the
|
175
|
+
raise RuntimeError.new(
|
176
|
+
"The #{ self.human_name } was unable to delegate the " +
|
177
|
+
"payload to the '#{ queue_name }' queue. #{ error.message }."
|
170
178
|
)
|
171
179
|
end
|
172
180
|
end
|
173
181
|
|
182
|
+
# Meta API read & error handling
|
183
|
+
protected; def read_object( property_id=nil, type, id, includes )
|
184
|
+
if property_id.present?
|
185
|
+
endpoint = "/properties/#{ property_id }/#{ type.pluralize }/#{ id }"
|
186
|
+
else
|
187
|
+
endpoint = "/properties/#{ id }"
|
188
|
+
end
|
189
|
+
|
190
|
+
object = operation( endpoint ).include( *includes ).read
|
191
|
+
if error?( object, type.capitalize ) && object.is_a?( Array )
|
192
|
+
object.first
|
193
|
+
else
|
194
|
+
object
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
protected; def error?( object, object_class )
|
199
|
+
class_name = "Boxxspring::#{ object_class }".constantize
|
200
|
+
!object.is_a?( class_name ) || object.send( :errors ).present?
|
201
|
+
end
|
202
|
+
|
203
|
+
protected; def operation( endpoint )
|
204
|
+
Boxxspring::Operation.new(
|
205
|
+
endpoint,
|
206
|
+
Boxxspring::Worker.configuration.api_credentials.to_hash
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
174
210
|
protected; def human_name
|
175
|
-
self.class.name.
|
176
|
-
underscore.
|
177
|
-
gsub( /[\/]/, ' ' ).
|
178
|
-
gsub( /_worker\Z/, '' )
|
211
|
+
self.class.name.underscore.gsub('_', ' ')
|
179
212
|
end
|
180
213
|
|
181
214
|
end
|
@@ -4,26 +4,10 @@ module Boxxspring
|
|
4
4
|
|
5
5
|
module Worker
|
6
6
|
|
7
|
-
def self.configuration( &block )
|
8
|
-
Configuration.instance().instance_eval( &block ) unless block.nil?
|
9
|
-
Configuration.instance()
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.env
|
13
|
-
self.configuration.env
|
14
|
-
end
|
15
|
-
|
16
7
|
class Configuration < Abstract
|
17
8
|
|
18
9
|
include Singleton
|
19
10
|
|
20
|
-
def initialize
|
21
|
-
super( {
|
22
|
-
env: ENV[ 'WORKERS_ENV' ] || 'development',
|
23
|
-
logger: Logger.new( STDOUT )
|
24
|
-
} )
|
25
|
-
end
|
26
|
-
|
27
11
|
def self.reloadable?
|
28
12
|
false
|
29
13
|
end
|
@@ -32,10 +16,31 @@ module Boxxspring
|
|
32
16
|
configuration.each_pair do | name, value |
|
33
17
|
self.send( "@#{name}", value )
|
34
18
|
end
|
35
|
-
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_token( options = {} )
|
22
|
+
|
23
|
+
token_details = Unimatrix::Authorization::ClientCredentialsGrant.new(
|
24
|
+
client_id: ENV[ 'KEYMAKER_CLIENT' ],
|
25
|
+
client_secret: ENV[ 'KEYMAKER_SECRET' ]
|
26
|
+
).request_token( options )
|
27
|
+
|
28
|
+
if token_details.include?( 'error' )
|
29
|
+
puts "ERROR: #{ token_details }"
|
30
|
+
end
|
36
31
|
|
32
|
+
if token_details.is_a?( Hash )
|
33
|
+
token_details.symbolize_keys!
|
34
|
+
token_details.update( expires_in: Time.now + token_details[ :expires_in ] ) if token_details[ :expires_in ]
|
35
|
+
api_credentials.access_token = token_details[ :access_token ]
|
36
|
+
api_credentials.token_expiry = token_details[ :expires_in ]
|
37
|
+
result = api_credentials
|
38
|
+
else
|
39
|
+
result = token_details
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
37
43
|
end
|
38
|
-
|
39
44
|
end
|
40
45
|
|
41
46
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Boxxspring
|
2
|
+
|
3
|
+
module Worker
|
4
|
+
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
PWD = Dir.pwd.freeze
|
8
|
+
|
9
|
+
def logger
|
10
|
+
|
11
|
+
@logger ||= begin
|
12
|
+
|
13
|
+
workers_env = ENV[ 'WORKERS_ENV' ]
|
14
|
+
|
15
|
+
if Worker.configuration.include?( 'logger' )
|
16
|
+
|
17
|
+
logger = Worker.configuration.logger
|
18
|
+
|
19
|
+
else
|
20
|
+
|
21
|
+
if self.log_local? || workers_env == 'test'
|
22
|
+
|
23
|
+
logger = Logger.new( STDOUT )
|
24
|
+
|
25
|
+
else
|
26
|
+
|
27
|
+
group_name = self.log_group_name
|
28
|
+
raise 'A logging group is required. You may need to set LOG_GROUP.' \
|
29
|
+
unless group_name.present?
|
30
|
+
|
31
|
+
worker_name = self.human_name.gsub( ' ','_' )
|
32
|
+
|
33
|
+
if workers_env == 'development'
|
34
|
+
username = ENV[ 'USER' ] || ENV[ 'USERNAME' ]
|
35
|
+
username = username.underscore.dasherize
|
36
|
+
|
37
|
+
group_name = "#{ username }.#{ group_name }"
|
38
|
+
elsif workers_env != 'production'
|
39
|
+
group_name = "#{ workers_env }.#{ group_name }"
|
40
|
+
end
|
41
|
+
|
42
|
+
logger = CloudWatchLogger.new(
|
43
|
+
{
|
44
|
+
access_key_id: ENV[ 'AWS_ACCESS_KEY_ID' ],
|
45
|
+
secret_access_key: ENV[ 'AWS_SECRET_ACCESS_KEY' ]
|
46
|
+
},
|
47
|
+
group_name,
|
48
|
+
worker_name
|
49
|
+
)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
logger.level = self.log_level
|
57
|
+
logger
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
protected; def log_group_name
|
64
|
+
group_name = ENV[ 'LOG_GROUP' ]
|
65
|
+
group_name ||= begin
|
66
|
+
File.open( File.join( PWD, 'GROUP' ), &:readline ) rescue nil
|
67
|
+
end
|
68
|
+
group_name ||= begin
|
69
|
+
name = `git config --get remote.origin.url` rescue nil
|
70
|
+
name.present? ? File.basename( name, '.*' ) : nil
|
71
|
+
end
|
72
|
+
group_name.strip
|
73
|
+
end
|
74
|
+
|
75
|
+
protected; def log_level
|
76
|
+
level = Logger::WARN
|
77
|
+
if ENV[ 'LOG_LEVEL' ].present?
|
78
|
+
level = ENV[ 'LOG_LEVEL' ].upcase
|
79
|
+
raise "An unkown log level was specificed by LOG_LEVEL." \
|
80
|
+
unless [ "INFO", "WARN", "ERROR", "DEBUG", "FATAL" ].include?( level )
|
81
|
+
level = "Logger::#{ level }".constantize
|
82
|
+
end
|
83
|
+
level
|
84
|
+
end
|
85
|
+
|
86
|
+
protected; def log_local?
|
87
|
+
log_local = ENV[ 'LOG_LOCAL' ] || 'false'
|
88
|
+
( log_local.to_s =~ /^true$/i ) == 0
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -18,7 +18,7 @@ module Boxxspring
|
|
18
18
|
self.class.processor.call( task )
|
19
19
|
else
|
20
20
|
raise RuntimeError.new(
|
21
|
-
"The #{self.human_name}
|
21
|
+
"The #{ self.human_name } lacks a task processor"
|
22
22
|
)
|
23
23
|
end
|
24
24
|
end
|
@@ -27,56 +27,49 @@ module Boxxspring
|
|
27
27
|
# implementation
|
28
28
|
|
29
29
|
protected; def process_payload( payload )
|
30
|
-
|
31
30
|
result = true
|
32
31
|
type_names = self.task_type_name.blank? ?
|
33
|
-
|
34
|
-
[ self.task_type_name ].flatten
|
32
|
+
nil : [ self.task_type_name ].flatten
|
35
33
|
states = self.task_state.blank? ?
|
36
|
-
|
37
|
-
[ self.task_state ].flatten
|
38
|
-
|
34
|
+
nil : [ self.task_state ].flatten
|
39
35
|
tasks = payload[ 'tasks' ]
|
40
|
-
|
36
|
+
|
37
|
+
if tasks.present? && tasks.respond_to?( :each )
|
41
38
|
tasks.each do | task |
|
42
39
|
task_id = task[ 'id' ]
|
43
|
-
if
|
40
|
+
if type_names.blank? || type_names.include?( task[ 'type_name' ] )
|
44
41
|
task = task_read( task[ 'property_id' ], task_id )
|
42
|
+
|
45
43
|
if task.is_a?( Boxxspring::Task )
|
46
|
-
if
|
44
|
+
if states.blank? || states.include?( task.state )
|
47
45
|
self.logger.info(
|
48
|
-
"
|
46
|
+
"Task #{ task.id } processing has started."
|
49
47
|
)
|
50
48
|
begin
|
51
49
|
result = self.process_task( task )
|
52
|
-
message = "
|
53
|
-
message += " and the message
|
54
|
-
self.logger.info(
|
55
|
-
message
|
56
|
-
)
|
50
|
+
message = "Task #{ task.id } processing has ended"
|
51
|
+
message += " and the message was retained." if result == false
|
52
|
+
self.logger.info( message )
|
57
53
|
rescue SignalException, StandardError => error
|
58
54
|
if error.is_a?( SignalException )
|
59
55
|
task_state = 'idle'
|
60
|
-
task_message = "
|
56
|
+
task_message = "Task #{ task.id } has restarted."
|
61
57
|
else
|
62
58
|
task_state = 'failed'
|
63
|
-
task_message = "
|
59
|
+
task_message = "Task #{ task.id } processing has failed."
|
64
60
|
end
|
65
|
-
task = task_write_state(task,
|
66
|
-
task_state,
|
67
|
-
task_message)
|
61
|
+
task = task_write_state( task, task_state, task_message )
|
68
62
|
self.logger.error( error.message )
|
69
|
-
self.logger.
|
63
|
+
self.logger.info( error.backtrace.join( "\n" ) )
|
70
64
|
raise error if error.is_a?( SignalException )
|
71
65
|
end
|
72
66
|
end
|
73
|
-
elsif task.is_a?(Array) &&
|
74
|
-
|
75
|
-
self.logger.error(task.first.message)
|
67
|
+
elsif task.is_a?( Array ) && task.first.respond_to?( :message )
|
68
|
+
self.logger.error( task.first.message )
|
76
69
|
else
|
77
70
|
self.logger.error(
|
78
|
-
"The #{self.human_name}
|
79
|
-
"task with the id #{task_id}."
|
71
|
+
"The #{self.human_name} is unable to retrieve the " +
|
72
|
+
"task with the id #{task_id}. #{task.inspect}"
|
80
73
|
)
|
81
74
|
end
|
82
75
|
end
|
@@ -84,14 +77,13 @@ module Boxxspring
|
|
84
77
|
end
|
85
78
|
|
86
79
|
result
|
87
|
-
|
88
80
|
end
|
89
81
|
|
90
82
|
protected; def task_read( property_id, task_id )
|
91
83
|
# why did this not work?
|
92
84
|
# self.task_operation( property_id ).where( id: task_id ).read
|
93
85
|
Boxxspring::Operation.new(
|
94
|
-
"/properties/#{property_id}/tasks/#{task_id}",
|
86
|
+
"/properties/#{ property_id }/tasks/#{ task_id }",
|
95
87
|
Worker.configuration.api_credentials.to_hash
|
96
88
|
).read
|
97
89
|
end
|
@@ -137,15 +129,8 @@ module Boxxspring
|
|
137
129
|
self.delegate_payload( queue_name, payload )
|
138
130
|
end
|
139
131
|
|
140
|
-
protected; def operation(endpoint)
|
141
|
-
Boxxspring::Operation.new(
|
142
|
-
endpoint,
|
143
|
-
Boxxspring::Worker.configuration.api_credentials.to_hash
|
144
|
-
)
|
145
|
-
end
|
146
|
-
|
147
132
|
end
|
148
133
|
|
149
134
|
end
|
150
135
|
|
151
|
-
end
|
136
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Boxxspring
|
2
|
+
|
3
|
+
module Worker
|
4
|
+
|
5
|
+
def self.configuration( &block )
|
6
|
+
Configuration.instance().instance_eval( &block ) unless block.nil?
|
7
|
+
Configuration.instance()
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.env
|
11
|
+
@environment ||= ENV[ 'WORKERS_ENV' ] || 'development'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.root
|
15
|
+
@root ||= begin
|
16
|
+
specification = Gem::Specification.find_by_name( 'boxxspring-workers' )
|
17
|
+
Pathname.new( specification.gem_dir )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/boxxspring-worker.rb
CHANGED
@@ -4,6 +4,8 @@ require 'active_support/all'
|
|
4
4
|
$LOAD_PATH.unshift( File.expand_path( '..', File.dirname( __FILE__ ) ) )
|
5
5
|
require 'lib/boxxspring/abstract'
|
6
6
|
require 'lib/boxxspring/journal'
|
7
|
+
require 'lib/boxxspring/worker'
|
8
|
+
require 'lib/boxxspring/worker/logging'
|
7
9
|
require 'lib/boxxspring/worker/configuration'
|
8
10
|
require 'lib/boxxspring/worker/base'
|
9
11
|
require 'lib/boxxspring/worker/task_base'
|
data/lib/tasks/workers.rake
CHANGED
@@ -1,38 +1,34 @@
|
|
1
|
+
require 'boxxspring-worker'
|
2
|
+
|
1
3
|
namespace :worker do
|
2
4
|
|
3
5
|
descendants = Boxxspring::Worker::Base.descendants
|
4
|
-
|
5
|
-
# remove base class workers
|
6
6
|
descendants.delete( Boxxspring::Worker::TaskBase )
|
7
7
|
|
8
8
|
descendants.each do | worker_class |
|
9
|
+
worker_name = worker_class.name.underscore.gsub(/_worker\Z/, '')
|
10
|
+
human_name = worker_class.name.underscore.gsub('_', ' ')
|
9
11
|
|
10
|
-
|
11
|
-
name.
|
12
|
-
underscore.
|
13
|
-
gsub( /[\/]/, '-' ).
|
14
|
-
gsub( /_worker\Z/, '' )
|
15
|
-
|
16
|
-
desc "#{worker_name.humanize.downcase} worker."
|
12
|
+
desc "#{ human_name }"
|
17
13
|
task worker_name.to_sym do
|
18
|
-
spinner = %w{| / - \\}
|
19
14
|
worker = worker_class.new
|
15
|
+
logger = worker.logger
|
16
|
+
|
17
|
+
spinner = %w{| / - \\}
|
20
18
|
print 'working... '
|
21
|
-
|
22
|
-
|
23
|
-
)
|
19
|
+
logger.info( "The #{ human_name } has started." )
|
20
|
+
|
24
21
|
begin
|
25
22
|
loop do
|
26
23
|
print "\b" + spinner.rotate!.first
|
27
24
|
worker.process
|
28
25
|
end
|
29
26
|
rescue SystemExit, Interrupt
|
30
|
-
|
31
|
-
"The #{worker_name.humanize.downcase} worker has stopped."
|
32
|
-
)
|
27
|
+
logger.info( "The #{ human_name } has stopped." )
|
33
28
|
puts 'stopped'
|
34
29
|
exit 130
|
35
30
|
end
|
36
31
|
end
|
37
32
|
end
|
38
|
-
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxxspring-workers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristoph Cichocki-Romanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -111,8 +111,10 @@ files:
|
|
111
111
|
- lib/boxxspring/synchronization/operations.rb
|
112
112
|
- lib/boxxspring/synchronization/orchestrator.rb
|
113
113
|
- lib/boxxspring/synchronization/variable.rb
|
114
|
+
- lib/boxxspring/worker.rb
|
114
115
|
- lib/boxxspring/worker/base.rb
|
115
116
|
- lib/boxxspring/worker/configuration.rb
|
117
|
+
- lib/boxxspring/worker/logging.rb
|
116
118
|
- lib/boxxspring/worker/task_base.rb
|
117
119
|
- lib/tasks/workers.rake
|
118
120
|
homepage: http://bedrocket.com
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
137
|
version: '0'
|
136
138
|
requirements: []
|
137
139
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.4.8
|
139
141
|
signing_key:
|
140
142
|
specification_version: 4
|
141
143
|
summary: Bedrocket Media Ventrures Boxxspring Worker framework.
|