Skip to content

solid_queue doesn't raise a warning when fugit should generate multiple CRONs #703

@kghandour

Description

@kghandour

SolidQueue uses fugit to parse recurring tasks schedules. If you enter a schedule in natural language that generates multiple CRONs, only the first CRON is considered, and the other CRONs are ignored without warning. It might be a good idea to raise an error or a warning when that happens.

Normal case

For normal cases, with schedule

schedule: every day at 00:40

The corresponding fugit translation would result in this object.

> require 'fugit'; Fugit.parse('every day at 00:40')


#<Fugit::Cron:0x00007f5e11978d50
 @cron_s=nil,
 @day_and=nil,
 @hours=[0],
 @minutes=[40],
 @monthdays=nil,
 @months=nil,
 @original="40 0 * * *",
 @seconds=[0],
 @timezone=nil,
 @weekdays=nil,
 @zone=nil>

For schedules that only generate a single CRON like this:

schedule: every day at 00:40 and 15:40

The corresponding fugit translation results in this object:

#<Fugit::Cron:0x00007f5e116858c8
 @cron_s=nil,
 @day_and=nil,
 @hours=[0, 15],
 @minutes=[40],
 @monthdays=nil,
 @months=nil,
 @original="40 0,15 * * *",
 @seconds=[0],
 @timezone=nil,
 @weekdays=nil,
 @zone=nil>

Breaking case

However, for schedules that cannot be converted via fugit to a single CRON, like this

schedule: every day at 00:40 and 15:20

The corresponding fugit trims off the second schedule entirely and only results in:

#<Fugit::Cron:0x00007f5e117d43a0
 @cron_s=nil,
 @day_and=nil,
 @hours=[0],
 @minutes=[40],
 @monthdays=nil,
 @months=nil,
 @original="40 0 * * *",
 @seconds=[0],
 @timezone=nil,
 @weekdays=nil,
 @zone=nil>

This results in solid_queue only running the recurring task at one time and not reporting a failure.

Possible solution

A possible solution would be to use Fugit::Nat to parse and have multi: fail set to true.

schedule: every day at 00:40 and 15:20
Fugit::Nat.parse('every day at 00:40 and 15:20', multi: :fail)
(app):7:in '<top (required)>': multiple crons in "every day at 00:40 and 15:20" - {monthday: (slot :monthday "*" {weak: true})} (ArgumentError)

Or, for a safer approach if solid_queue can support multi CRONs,

Fugit::Nat.parse('every day at 00:40 and 15:20', multi: true)
 =>
[#<Fugit::Cron:0x00007f5e116ab0f0
  @cron_s=nil,
  @day_and=nil,
  @hours=[0],
  @minutes=[40],
  @monthdays=nil,
  @months=nil,
  @original="40 0 * * *",
  @seconds=[0],
  @timezone=nil,
  @weekdays=nil,
  @zone=nil>,
 #<Fugit::Cron:0x00007f5e116aae70
  @cron_s=nil,
  @day_and=nil,
  @hours=[15],
  @minutes=[20],
  @monthdays=nil,
  @months=nil,
  @original="20 15 * * *",
  @seconds=[0],
  @timezone=nil,
  @weekdays=nil,
  @zone=nil>]

Hope the description helps. Thought it would be a good idea to report this in case someone else goes through something similar and cannot debug why the recurring task is not running as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions