Class: Jets::Rails::Job::Queue::Url

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/jets/rails/job/queue/url.rb

Class Method Summary collapse

Class Method Details

.queue_url(queue_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jets/rails/job/queue/url.rb', line 6

def queue_url(queue_name)
  # On AWS Lambda JETS_QUEUE_URL must be set
  # It must be set when on AWS to avoid the API call to retrieve the queue_url
  env_var = "JETS_QUEUE_URL_#{queue_name.upcase}" # IE: JETS_QUEUE_URL_DEFAULT
  if ENV["AWS_LAMBDA_FUNCTION_NAME"]
    if ENV[env_var] # queue_url
      return ENV[env_var]
    else
      # Not never happen on AWS Lambda
      # Unless env var is removed from the lambda function
      puts "        WARN: JETS_QUEUE_URL_\#{queue_name.upcase} not set.  Unable to get queue url.\n        Maybe double check for:\n\n        config/jets/deploy.rb\n\n            config.job.additional_queues = [\"\#{queue_name}\"]\n\n        A queue name must be defined for the SQS queue to be created.\n      EOL\n    end\n  end\n\n  # Locally can also be set to avoid the API call for testing\n  return ENV[env_var] if ENV[env_var]\n\n  # Only reach here locally.\n  # Will try getting queue url from API latest release\n  # 1. can be nil\n  # 2. can raise NotFound error\n  resp = Jets::Api::Release.retrieve(\"latest\")\n  endpoint = resp.endpoints.find { |x| x[\"name\"] == \"queue_url_\#{queue_name}\" }\n  endpoint&.url\nrescue Jets::Api::Error::NotFound => e\n  puts \"WARN: Unable to get queue url from API: \#{e.message}\".color(:yellow)\n  puts <<~EOL\n    INFO: You can set \#{env_var} in your environment to avoid this API call.\n    Locally, jets will try to get the latest release from the API to get the queue_url.\n    This will only work if the stack has been deployed successfully.\n  EOL\n  raise\nend\n"