GithubHelp home page GithubHelp logo

crony's Introduction

CRONY

Crony is a template project to implement a cron like scheduler. rufus-scheduler is used for scheduling and foreman is used for running the scheduler. This makes it perfect for a deployment on heroku's Caledon Cedar stack.

Usage

Fork/clone this project, install the gems needed using bundler:

bundle install

and start the scheduler using foreman:

bundle exec foreman start

Your crony won't do much yet (except for printing it's heartbeat), so add some cron jobs now. And better delete that example job before you use it seriously.

Adding Cron Jobs

Each (non hidden) file in the cron.d directory will be evaluated and can be used to schedule jobs. Refer to rufus-scheduler's documentation on how to schedule jobs. Be aware that your cron.d files will be evaluated in the context of the scheduler instance, so you can access all methods the scheduler has. Here's an example:

every "5m" do
  # do something every five minutes
end

You can have as many jobs as you wish within one file. Separating them in several files is just a way to organize and group your jobs for better overview.

Within your cron.d files, you can do anything: Requiring other files/gems (remember to put them into your Gemfile first), defining classes/methods etc. This way, you can do anything from sending emails to pinging other sites of yours (eg using the fabulous httpi) to start a task there or to keep them alive when the hoster shuts them down after a certain time of inactivity.

Heroku Deployment

After you've added your jobs and helpers, you're ready to deploy your jobs to heroku:

# create an application on the Caledon Cedar stack
heroku create --stack cedar

# tell heroku not to install the gems you only need for your local development/testing
heroku config:add BUNDLE_WITHOUT=development

# deploy your code
git push heroku master

# scale your worker (one is well within heroku's limits for a free app)
heroku ps:scale worker=1

After this, your private crony instance will happily be running and executing your jobs.

If you want to pause the scheduler, just scale your worker down to 0:

heroku ps:scale worker=0

To restart, scale it back up to 1 again.

Be aware that heroku cycles your processes every 24h meaning that your crony instance will be restarted once daily. There shouldn't be any problems, though - unless this collides exactly with a job you've scheduled.

Future Ideas

  • Implement database backed (instead of file based) job configuration that would allow for management of jobs via the command line (eg rake tasks) without the need to redeploy the app.
  • Integrate a web view - currently, accessing the URL of your app will result in an error since the only process won't serve HTTP requests.

Contributing

If you want to contribute changes you've made, helper scripts or anything else, please fork this project and send a pull request with your changes.

Preferably, you keep the master branch in your fork clean and create another branch to add your own jobs and push that to heroku. This way, you can keep the master branch clean from personal files and make those pull requests easier for both of us. Just rebase your personal branch on top of master and use -f when pushing to heroku.

License

MIT

Copyright (c) 2011 Thomas Jachmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

crony's People

Contributors

thomasjachmann avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mre

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.