Allows usage of ISO8601 Duration strings for run_every
#33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 exampleP1M
is equivalent to1.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 withActiveSupport::Duration.parse
I just do a simple regex check that the
run_every
object is a String starting with aP
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!