Timezone-aware Job Scheduler DSL and Converter
MIT License
Timezone-aware Job Scheduler DSL and Converter
job_template "/bin/bash -l -c ':job'"
job_type :rake, "bundle exec rake :task RAILS_ENV=production"
default do
timezone "Asia/Tokyo" # UTC+9
end
every 1.hour, at: 15 do
name "Send awesome mails"
rake "send_awesome_mail"
end
every :day, at: '0:00 am' do
name "Send greeting notifications"
description "Send greeting notifications for all users"
rake "send_greeting_notification"
end
every :day, at: '0:00 am', timezone: "Europe/Berlin" do # UTC+1
name "Send notifications for Berlin"
description "Send notifications for Berlin"
rake "send_notification[Europe/Berlin]"
end
every :wednesday, at: '0:10 am' do
name "Create new companies"
rake "create_new_companies"
end
every "0 10 10,20 * *" do
name "Healthcheck"
rake "ping"
end
As you know, Cron is commonly used for scheduled jobs. However, Cron has some difficulties:
Recently there are solutions for the last point, e.g. Azure Scheduler, CloudWatch Events and Kubernetes Cron Job, but those services still have fixed timezone to UTC.
Whenever gem is very useful to describe scheduled jobs in human-friendly format. However, Whenever cannot treat timezone and metadata so that it is just a wrapper of Cron expression.
To resolve above problems, we need:
Ruby 2.2.2 or above
Add this line to your application's Gemfile:
gem 'xronor'
And then execute:
$ bundle
Or install it yourself as:
$ gem install xronor
Commands:
xronor crontab SCHEDULEFILE
xronor cwa SCHEDULEFILE --cluster=CLUSTER --container=CONTAINER --function=FUNCTION --table=TABLE --task-definition=TASK_DEFINITION
xronor template SCHEDULEFILE --template=TEMPLATE
xronor template_per_job SCHEDULERFILE --outdir=OUTDIR --template=TEMPLATE
Xronor CLI converts DSL file to:
xronor cwa
CloudWatch Events Rule (requires AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
and AWS_REGION
environment variables)xronor crontab
crontab filexronor template
write all jobs in one filexronor template_per_job
generate files per job👉 docs/dsl
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/dtan4/xronor.
Daisuke Fujita (@dtan4)
The gem is available as open source under the terms of the MIT License.