Skip to content

Handle ZeroDivisionError from CronParser when passing values < 1

Michael Trainor requested to merge tmike-fugit-zerodivision into master

What does this MR do and why?

Fixes #456886 (closed)

The ci_daily_pipeline_schedule_triggers limit value is currently not validated by the model, so it can be any value within the underlying datatype for the column. This can be a number larger than 1440, or even a negative number.

When a number greater than 1440 is configured for the daily limit, the integer provided in the natural expression to Fugit contains zero. This results in a ZeroDivisionError from Fugit gem, which is used by our CronParser.

This MR ensures that the ZeroDivisionError is handled by the calling service, and the fallback method will be used instead, as it should be treated as an invalid cron.

The docs state currently that there is no maximum value for this limit, but:

  • Values above 1440 currently cause the every_x_minutes to be less than 1
  • Fugit returns ZeroDivisionError when parsing the expression every 0 minutes
  • Positive values less than 1 would result in scheduling outside of a single day, and the limit should be within the constraints of a single day

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Create a Pipeline schedule for a project
  2. Enter Rails Console
  3. Update the limit as per our docs, but use a number higher than 1440
  4. Attempt to run the pipeline schedule immediately
Edited by Michael Trainor

Merge request reports

Loading