-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Elastic Beanstalk's Periodic Tasks? (via cron.yml) #40
Comments
If not, here is my basic implementation that I am using now: version: 1
cron:
- name: 'HeartbeatJob'
url: '/_jobs'
schedule: "*/30 * * * * *"
- name: 'FetchStreamMetricsJob'
url: '/_jobs'
schedule: "*/5 * * * * *" Rails.application.routes.draw do
post '_jobs', to: 'job_runner#perform_now'
end class JobRunnerController < ApplicationController
protect_from_forgery :except => :perform_now
def perform_now
return head(:unauthorized) if ENV['DISABLE_SQS_CONSUMER']
job_name = request.headers['X-Aws-Sqsd-Taskname']
job = job_name.constantize.new
job.perform_now
return head(:ok)
end
end |
Hi @briantigerchow, Currently this gem does not support periodic tasks, but I have been evaluating this possibility of including a support for this feature. Thanks a lot for your submission and for sharing your implementation. I'll leave this issue open and I'll come back to it in the near future. |
Good question. I am looking forward to hear your advice on how to set it up according to best practices. |
FWIW I've implemented the same as @briantigerchow (cron.yml) except that I wrap the
Whilst setting up separate Rails environments may seem like overkill, I have other requirements such as my web app is configured to force SSL but the worker app responds on port 80. UPDATE: I should add that this approach does not expose web urls in the worker tier, so if you need to refer to web tier urls (e.g., in an email), follow @briantigerchow's approach. |
I just implemented your proposal. Thanks |
Instead of using the methods above, I added a check to the middleware. If a request appears to be coming from SQS but doesn't originate from the ActiveElasticJob gem, we check to see if it matches the "_jobs" route. If so, it's considered to be from the cron.yml file and we perform the action immediately. It's a bit ugly though. This allows me to leave config.force_ssl on even for cron jobs.
|
How does the new built-in support for this behavior work? |
Hi all, Support for periodic tasks has just been released in version v2.0.0. I also added documentation on its usage to the README. |
Does this library support Elastic Beanstalk's periodic tasks via
cron.yml
file? I do not see documentation for such a feature.The text was updated successfully, but these errors were encountered: