Project

qron

0.0
The project is in a healthy, maintained state
A Ruby thread that wakes up in time to perform what's ordered in its crontab
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0

Runtime

~> 1.11
~> 1.0
 Project Readme

qron

tests Gem Version

Queue and cron.

A stupid Ruby cron thread that wakes up from time to time to perform according to what's written in a crontab.

Given etc/qrontab_dev:

  @reboot       p [ :hello, "just started" ]
  * * * * *     p [ :hello, :min, Time.now ]
  * * * * * *   p [ :hello, :sec, Time.now ]

and

require 'qron'

q = Qron.new(tab: 'etc/qrontab_dev')
q.join
[:hello, :sec, 2025-03-23 15:39:56.558783631 +0900]
[:hello, :sec, 2025-03-23 15:39:57.368985197 +0900]
[:hello, :sec, 2025-03-23 15:39:58.308865845 +0900]
[:hello, :sec, 2025-03-23 15:39:59.209102149 +0900]
[:hello, :min, 2025-03-23 15:40:00.149162785 +0900]
[:hello, :sec, 2025-03-23 15:40:00.149290935 +0900]
[:hello, :sec, 2025-03-23 15:40:01.039228675 +0900]
(...)

Uses fugit for cron parsing and stagnum as its worker pool.

A little brother to rufus-scheduler.

reload: true

Specifying reload: true when initializing tells the Qron instance to reload its crontab file at every tick.

(Qron ticks usually every minute, unless it has one or more second precision crons specified, in which case it ticks every second).

require 'qron'

q = Qron.new(tab: 'etc/qrontab_dev', reload: true)

Timezones

It's OK to use timezones in the qrontab file:

  30 * * * *     Asia/Tokyo        p [ :tokyo, :min, Time.now ]
  30 4 1,15 * 5  Europe/Budapest   p [ :budapest, :min, Time.now ]

"Settings"

A qrontab file accepts, cron and commands but also "settings" that set variables in the context passed to commands:

  #
  # settings

  a = 1 + 2
  b = Time.now

  #
  # actual crons

  * * * * * *  pp [ :ctx, ctx ]

where the puts might output something like:

[ :ctx,
  { time: 'Time instance...',
    cron: 'Fugit::Cron instance...',
    command: 'pp [ :ctx, ctx ]',
    qron: 'The Qron instance...',
    a: 3,
    b: 'Time instance...' } ]

A context is instantied and prepare for each command when it triggers.

LICENSE

MIT, see LICENSE.txt