jets-rails 1.0.3 → 1.1.0
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/CHANGELOG.md +3 -0
- data/lib/jets/rails/job/queue/check.rb +31 -25
- data/lib/jets/rails/job/queue/url.rb +37 -17
- data/lib/jets/rails/job/queue.rb +6 -2
- data/lib/jets/rails/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: 91030594fed4848d30a8a55d3d68d7c850098e24a5962d101f2eb3e15985d1f6
|
4
|
+
data.tar.gz: 2b5e1a889f0e8bf54bb526f2040dec2b250d193a37c3f24905e3f46628aceb82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3eea513b43fbd728dbe8e2136cc6d0c519c4929c468e4444c573dda16d86cfe0ac719c9a0ff30068377da63da3433a9dc0bd31bc7605c56083fed9b7b836bc
|
7
|
+
data.tar.gz: 3f589e0f1f016db3ca1f70c10e8f435256d38e7acf7ee33324815a9988e935f9870ae0ef9a2db4378b5fc2180625707bb5ea4491bb8b7d51a5ac59a26b00f3ab
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [1.1.0] - 2024-05-30
|
7
|
+
- [#14](https://github.com/rubyonjets/jets-rails/pull/14) multiple queue support
|
8
|
+
|
6
9
|
## [1.0.3] - 2024-05-29
|
7
10
|
- [#13](https://github.com/rubyonjets/jets-rails/pull/13) update gem pin rails >= 5.0
|
8
11
|
|
@@ -2,31 +2,37 @@ class Jets::Rails::Job::Queue
|
|
2
2
|
class Check
|
3
3
|
class Error < StandardError; end
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
include Jets::Util::Logging
|
6
|
+
|
7
|
+
def initialize(job)
|
8
|
+
@job = job
|
9
|
+
end
|
10
|
+
|
11
|
+
@@error_message = "ERROR: Unable to get queue url".color(:red)
|
12
|
+
def exist!
|
13
|
+
job_enable_message
|
14
|
+
existance!
|
15
|
+
end
|
16
|
+
|
17
|
+
def queue_url
|
18
|
+
Url.queue_url(@job.queue_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def existance!
|
22
|
+
return if queue_url
|
23
|
+
|
24
|
+
log.error @@error_message
|
25
|
+
raise Error, "Are you sure you have deployed with Jets.project.config.job.enable = true ?"
|
26
|
+
rescue Jets::Api::Error::NotFound
|
27
|
+
log.error @@error_message
|
28
|
+
raise Error, "It does not look like the stack has successfully deployed. Please deploy first."
|
29
|
+
end
|
30
|
+
|
31
|
+
def job_enable_message
|
32
|
+
return if queue_url
|
33
|
+
|
34
|
+
log.error @@error_message
|
35
|
+
raise Error, "Are you sure that config.job.enable = true ?"
|
30
36
|
end
|
31
37
|
end
|
32
38
|
end
|
@@ -3,27 +3,47 @@ class Jets::Rails::Job::Queue
|
|
3
3
|
class << self
|
4
4
|
extend Memoist
|
5
5
|
|
6
|
-
def queue_url
|
7
|
-
# On AWS Lambda
|
6
|
+
def queue_url(queue_name)
|
7
|
+
# On AWS Lambda JETS_QUEUE_URL must be set
|
8
8
|
# It must be set when on AWS to avoid the API call to retrieve the queue_url
|
9
|
-
|
9
|
+
env_var = "JETS_QUEUE_URL_#{queue_name.upcase}" # IE: JETS_QUEUE_URL_DEFAULT
|
10
|
+
if ENV["AWS_LAMBDA_FUNCTION_NAME"]
|
11
|
+
if ENV[env_var] # queue_url
|
12
|
+
return ENV[env_var]
|
13
|
+
else
|
14
|
+
# Not never happen on AWS Lambda
|
15
|
+
# Unless env var is removed from the lambda function
|
16
|
+
puts <<~EOL
|
17
|
+
WARN: JETS_QUEUE_URL_#{queue_name.upcase} not set. Unable to get queue url.
|
18
|
+
Maybe double check for:
|
10
19
|
|
11
|
-
|
20
|
+
config/jets/deploy.rb
|
21
|
+
|
22
|
+
config.job.additional_queues = ["#{queue_name}"]
|
23
|
+
|
24
|
+
A queue name must be defined for the SQS queue to be created.
|
25
|
+
EOL
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Locally can also be set to avoid the API call for testing
|
30
|
+
return ENV[env_var] if ENV[env_var]
|
31
|
+
|
32
|
+
# Only reach here locally.
|
33
|
+
# Will try getting queue url from API latest release
|
12
34
|
# 1. can be nil
|
13
35
|
# 2. can raise NotFound error
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
raise
|
26
|
-
end
|
36
|
+
resp = Jets::Api::Release.retrieve("latest")
|
37
|
+
endpoint = resp.endpoints.find { |x| x["name"] == "queue_url_#{queue_name}" }
|
38
|
+
endpoint&.url
|
39
|
+
rescue Jets::Api::Error::NotFound => e
|
40
|
+
puts "WARN: Unable to get queue url from API: #{e.message}".color(:yellow)
|
41
|
+
puts <<~EOL
|
42
|
+
INFO: You can set #{env_var} in your environment to avoid this API call.
|
43
|
+
Locally, jets will try to get the latest release from the API to get the queue_url.
|
44
|
+
This will only work if the stack has been deployed successfully.
|
45
|
+
EOL
|
46
|
+
raise
|
27
47
|
end
|
28
48
|
memoize :queue_url
|
29
49
|
end
|
data/lib/jets/rails/job/queue.rb
CHANGED
@@ -6,7 +6,6 @@ module Jets::Rails::Job
|
|
6
6
|
|
7
7
|
extend Memoist
|
8
8
|
include Jets::Util::Logging
|
9
|
-
delegate :queue_url, to: Url
|
10
9
|
|
11
10
|
attr_reader :job, :timestamp
|
12
11
|
def initialize(job, timestamp = nil)
|
@@ -15,7 +14,7 @@ module Jets::Rails::Job
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def enqueue
|
18
|
-
Check.exist!
|
17
|
+
Check.new(@job).exist!
|
19
18
|
|
20
19
|
params = {
|
21
20
|
queue_url: queue_url,
|
@@ -35,6 +34,11 @@ module Jets::Rails::Job
|
|
35
34
|
queue_url.include?(".fifo")
|
36
35
|
end
|
37
36
|
|
37
|
+
def queue_url
|
38
|
+
Url.queue_url(@job.queue_name)
|
39
|
+
end
|
40
|
+
memoize :queue_url
|
41
|
+
|
38
42
|
def fifo_params
|
39
43
|
options = {}
|
40
44
|
options[:message_deduplication_id] = message_deduplication_id
|
data/lib/jets/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|