Skip to content

Commit

Permalink
Make route for periodic tasks messages configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tawan committed Nov 27, 2016
1 parent e8be8c2 commit b975d77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This gem is configurable in case your setup requires different settings than the
config.active_elastic_job.process_jobs = # defaults to ENV['PROCESS_ACTIVE_ELASTIC_JOBS'] == 'true' || false
config.active_elastic_job.aws_credentials = # defaults to Aws::InstanceProfileCredentials.new
config.active_elastic_job.secret_key_base = # defaults to Rails.application.secrets[:secret_key_base]
cofnig.active_elastic_job.periodic_tasks_route = # defaults to '/periodic_tasks'.freeze
end
```

Expand Down
7 changes: 5 additions & 2 deletions lib/active_elastic_job/rack/sqs_message_consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SqsMessageConsumer
[ 'Request forbidden!'.freeze ]
]
DOCKER_HOST_IP = '172.17.0.1'.freeze
PERIODIC_TASKS_PATH = '/periodic_tasks'.freeze

def initialize(app) #:nodoc:
@app = app
Expand Down Expand Up @@ -88,8 +87,12 @@ def aws_sqsd?(request)
current_user_agent[0..('aws-sqsd'.freeze.size - 1)] == 'aws-sqsd'.freeze)
end

def periodic_tasks_route
@periodic_tasks_route ||= config.periodic_tasks_route
end

def periodic_task?(request)
!request.fullpath.nil? && request.fullpath[0..(PERIODIC_TASKS_PATH.size - 1)] == PERIODIC_TASKS_PATH
!request.fullpath.nil? && request.fullpath[0..(periodic_tasks_route.size - 1)] == periodic_tasks_route
end

def execute_job(request)
Expand Down
1 change: 1 addition & 0 deletions lib/active_elastic_job/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Railtie < Rails::Railtie
config.active_elastic_job = ActiveSupport::OrderedOptions.new
config.active_elastic_job.process_jobs = ENV['PROCESS_ACTIVE_ELASTIC_JOBS'] == 'true' || false
config.active_elastic_job.aws_credentials = Aws::InstanceProfileCredentials.new
config.active_elastic_job.periodic_tasks_route = '/periodic_tasks'.freeze

initializer "active_elastic_job.insert_middleware" do |app|
if app.config.active_elastic_job.secret_key_base.blank?
Expand Down
1 change: 1 addition & 0 deletions spec/active_elastic_job/rack/sqs_message_consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

before do
allow(sqs_message_consumer).to receive(:secret_key_base) { secret_key_base }
allow(sqs_message_consumer).to receive(:periodic_tasks_route) { '/periodic_tasks' }
allow(sqs_message_consumer).to receive(:enabled?) { true }
end

Expand Down

0 comments on commit b975d77

Please sign in to comment.