barbeque 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/app/controllers/barbeque/api/job_executions_controller.rb +6 -0
- data/app/controllers/barbeque/sns_subscriptions_controller.rb +1 -1
- data/app/models/barbeque/api/job_execution_resource.rb +8 -3
- data/app/services/barbeque/message_enqueuing_service.rb +15 -1
- data/lib/barbeque/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '098d46ae421c14386c5231061b4c098931bbe762b3e3fcec5149beef806ce46b'
|
4
|
+
data.tar.gz: df03e121930f8d03ce5cc34e1e6f29b35130cb9b2f0c2b5c2c33a3de1a81fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d53cdd09556249fc858311bdaab4efb43f0d2f4189a29cec76d83e8b8bbd471b3fe14ff2d1eb57674036829eeff094fe928065fbab765d737280380e157ece6
|
7
|
+
data.tar.gz: de83d760cabef91439014926294fc181404cf29adfbafe7463901da0a5ddc8d75ae6ab973cbb72601019123acaf4b45b20832adc11a7445dfc24545f94f7159d
|
data/README.md
CHANGED
@@ -38,6 +38,11 @@ And deploy it as you like.
|
|
38
38
|
|
39
39
|
You also need to prepare MySQL, Amazon SQS and Amazon S3.
|
40
40
|
|
41
|
+
#### For sandbox environment
|
42
|
+
Barbeque's enqueue API tries to be independent of MySQL by design.
|
43
|
+
Although that design policy, verifying the enqueued job is useful in some environment (such as sandboxed environment).
|
44
|
+
Passing `BARBEQUE_VERIFY_ENQUEUED_JOBS=1` to the Web API server enables the feature that verifies the enqueued job by accessing MySQL.
|
45
|
+
|
41
46
|
### Worker
|
42
47
|
|
43
48
|
```bash
|
@@ -6,6 +6,11 @@ class Barbeque::Api::JobExecutionsController < Barbeque::Api::ApplicationControl
|
|
6
6
|
string :job, required: true, description: 'Class of Job to be enqueued'
|
7
7
|
string :queue, required: true, description: 'Queue name to enqueue a job'
|
8
8
|
any :message, required: true, description: 'Free-format JSON'
|
9
|
+
integer :delay_seconds, description: 'Set message timer of SQS'
|
10
|
+
end
|
11
|
+
|
12
|
+
rescue_from Barbeque::MessageEnqueuingService::BadRequest do |exc|
|
13
|
+
render status: 400, json: { error: exc.message }
|
9
14
|
end
|
10
15
|
|
11
16
|
private
|
@@ -32,6 +37,7 @@ class Barbeque::Api::JobExecutionsController < Barbeque::Api::ApplicationControl
|
|
32
37
|
job: params[:job],
|
33
38
|
queue: params[:queue],
|
34
39
|
message: params[:message],
|
40
|
+
delay_seconds: params[:delay_seconds],
|
35
41
|
).run
|
36
42
|
end
|
37
43
|
|
@@ -44,6 +44,6 @@ class Barbeque::SnsSubscriptionsController < Barbeque::ApplicationController
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def fetch_sns_topic_arns
|
47
|
-
Barbeque::SNSSubscriptionService.sns_client.list_topics.topics.map(&:topic_arn)
|
47
|
+
Barbeque::SNSSubscriptionService.sns_client.list_topics.flat_map(&:topics).map(&:topic_arn)
|
48
48
|
end
|
49
49
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
class Barbeque::Api::JobExecutionResource < Barbeque::Api::ApplicationResource
|
2
2
|
property :message_id
|
3
|
-
|
4
3
|
property :status
|
5
|
-
|
6
4
|
property :id
|
7
|
-
|
8
5
|
property :html_url, selectable: true
|
6
|
+
property :message, selectable: true
|
9
7
|
|
10
8
|
delegate :message_id, :status, :id, to: :model
|
11
9
|
|
@@ -21,4 +19,11 @@ class Barbeque::Api::JobExecutionResource < Barbeque::Api::ApplicationResource
|
|
21
19
|
nil
|
22
20
|
end
|
23
21
|
end
|
22
|
+
|
23
|
+
def message
|
24
|
+
log = @model.execution_log
|
25
|
+
if log
|
26
|
+
log['message']
|
27
|
+
end
|
28
|
+
end
|
24
29
|
end
|
@@ -2,6 +2,10 @@ require 'aws-sdk-sqs'
|
|
2
2
|
|
3
3
|
class Barbeque::MessageEnqueuingService
|
4
4
|
DEFAULT_QUEUE = ENV['BARBEQUE_DEFAULT_QUEUE'] || 'default'
|
5
|
+
VERIFY_ENQUEUED_JOBS = ENV['BARBEQUE_VERIFY_ENQUEUED_JOBS'] || '0'
|
6
|
+
|
7
|
+
class BadRequest < StandardError
|
8
|
+
end
|
5
9
|
|
6
10
|
def self.sqs_client
|
7
11
|
@sqs_client ||= Aws::SQS::Client.new
|
@@ -11,21 +15,31 @@ class Barbeque::MessageEnqueuingService
|
|
11
15
|
# @param [String] job
|
12
16
|
# @param [Object] message
|
13
17
|
# @param [String] queue
|
14
|
-
|
18
|
+
# @param [Integer, nil] delay_seconds
|
19
|
+
def initialize(application:, job:, message:, queue: nil, delay_seconds: nil)
|
15
20
|
@application = application
|
16
21
|
@job = job
|
17
22
|
@queue = queue || DEFAULT_QUEUE
|
18
23
|
@message = message
|
24
|
+
@delay_seconds = delay_seconds
|
19
25
|
end
|
20
26
|
|
21
27
|
# @return [String] message_id
|
22
28
|
def run
|
23
29
|
queue_url = Barbeque::JobQueue.queue_url_from_name(@queue)
|
30
|
+
if VERIFY_ENQUEUED_JOBS == '1'
|
31
|
+
unless Barbeque::JobDefinition.joins(:app).merge(Barbeque::App.where(name: @application)).where(job: @job).exists?
|
32
|
+
raise BadRequest.new("JobDefinition '#{@job}' isn't defined in '#{@application}' application")
|
33
|
+
end
|
34
|
+
end
|
24
35
|
response = Barbeque::MessageEnqueuingService.sqs_client.send_message(
|
25
36
|
queue_url: queue_url,
|
26
37
|
message_body: build_message.to_json,
|
38
|
+
delay_seconds: @delay_seconds,
|
27
39
|
)
|
28
40
|
response.message_id
|
41
|
+
rescue Aws::SQS::Errors::InvalidParameterValue => e
|
42
|
+
raise BadRequest.new(e.message)
|
29
43
|
end
|
30
44
|
|
31
45
|
private
|
data/lib/barbeque/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barbeque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: adminlte2-rails
|