Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows usage of ISO8601 Duration strings for run_every #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cannikin
Copy link

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!

When setting `run_every` you can pass an ISO8601 Duration string like `P1M` which will use ActiveSupport::Duration's built-in parser to turn it into a Rails `1.month` duration object. See https://en.wikipedia.org/wiki/ISO_8601#Durations for full spec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant