Socket
Book a DemoInstallSign in
Socket

rcron

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rcron

0.1.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

rcron

A simple cron-like scheduler for Ruby.

Installation

Add this line to your application's Gemfile:

gem 'rcron'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rcron

Cron format

As of now, most of the expressions except for ? and W are supported.

http://en.wikipedia.org/wiki/Cron#Format

Examples

Basic

require 'rcron'
rcron = RCron.new

# Enqueue a task running every two minutes
rcron.enq('task #1', '*/2 * * * *') do |task|
  # Task logic
  # ...
end

# You can `enq' any number of tasks before starting rcron

rcron.start

One-time only task

rcron = RCron.new
# will run once at 8pm next second friday
rcron.enq('task #2', '0 8 * * fri#2') do |task|
  # Removes the task from the queue
  task.deq

  # Task logic
  # ...
end
rcron.start

Options

rcron = RCron.new

# :exclusive - Only one instance of this task will run simultaneously.
# :timeout   - Task will be terminated if it takes longer than the specified seconds.
rcron.enq('Every ten-minutes during summer', 
        '*/10 * * jun-aug *', 
        :exclusive => true, 
        :timeout => 1200) do |task|
  # Task logic
  # ...
end

# log to $stderr instead of default $stdout
rcron.start Logger.new($stderr)

Notes

  • Minimum interval for each task is one-minute just like cron. So rcron usually sleeps most of the time and wakes up only once a minute. (Except when short timeouts for the tasks are specified. In that case, rcron wakes up more frequently to check whether the task should be terminated)
  • rcron checks to start tasks at the very first second of every minute. e.g. When you first start it at 12:00:45, it will sleep 15 seconds before doing anything.
  • Tested on Ruby 1.8.7, Ruby 1.9.3 and JRuby 1.6.7.2

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Added some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Copyright (c) 2011 Junegunn Choi. See LICENSE.txt for further details.

FAQs

Package last updated on 12 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.