amitree / delayed_job_recurring

Extends delayed_job to support recurring jobs
MIT License
84 stars 33 forks source link

Allows usage of ISO8601 Duration strings for `run_every` #33

Open cannikin opened 4 years ago

cannikin commented 4 years ago

I have an interesting use case where I'm making a GraphQL API for creating recurring background jobs. Rather than have to dangerously exec Ruby syntax for setting durations like 1.month I discovered that the ISO8601 spec has support for Durations. For example P1M is equivalent to 1.month. This PR adds support for this syntax in addition to ActiveSupport::Duration and integers. It uses the built-in support for ISO Duration parsing available with ActiveSupport::Duration.parse

I just do a simple regex check that the run_every object is a String starting with a P and let the parser take it from there. If there are any syntax errors they will be found by the AS::Duration parser.

I didn't add any specs because I didn't know if this was something the maintainers would even be interested in supporting. If so, let me know and I'll add specs and update the docs!