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

Add validation for recurrence rules #122

Closed
wants to merge 5 commits into from
Closed

Add validation for recurrence rules #122

wants to merge 5 commits into from

Conversation

jonhester
Copy link
Contributor

This takes care of #108 and will prevent things like #121 from happening. Throws error if not valid. Validation runs at the beginning of next invocation. @tejasmanohar and @santigimeno, what do you think?

@tejasmanohar
Copy link
Member

+1 from me. Solves existing issues, I'm for it...

return true;
};

RecurrenceRule.prototype.nextInvocationDate = function(base) {
if (!this.validate()) {
throw new Error('Invalid RecurrenceRule');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would we great that validate also returned info about what field is invalid. Then we could throw and error with a message like this: Invalid RecurrenceRule. Field year is out of range

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santigimeno Good idea. I'll add this.

@jonhester
Copy link
Contributor Author

I'll update this later today.

@jonhester
Copy link
Contributor Author

@tejasmanohar @santigimeno see if this is better

@santigimeno
Copy link
Member

In the tests we should check that the error message is the expected.
Other than that LGTM

@jonhester
Copy link
Contributor Author

@santigimeno Good call. I'll add the checks.

@tejasmanohar
Copy link
Member

LGTM now. What about you, @santigimeno ?

@santigimeno
Copy link
Member

@jonhester Why are you validating at the beginning of every invocation. Wouldn't just validate once at scheduling suffice?

@jonhester
Copy link
Contributor Author

@santigimeno You are correct that this is not ideal, but since nextInvocation is exposed as part of the api, this seems to me to be the only way to ensure that RecurrenceRule will always get validated. Something that should definitely be accounted for in a refactor. Check the RecurrenceRule tests to see what I mean. Here is an example from the first recurrence rule test:

var rule = new schedule.RecurrenceRule();
      rule.second = 5;

      var next = rule.nextInvocationDate(base);

@santigimeno
Copy link
Member

Why dont you add a validated property to RecurrenceRule so it only validates the object once?

@jonhester
Copy link
Contributor Author

That could be done but could still not catch the error if someone does this:

var rule = new schedule.RecurrenceRule();
      rule.second = 5;

      var next = rule.nextInvocationDate(base);

      rule.second = 60

      next = rule.nextInvocationDate(base);

Which is abusing the API for sure, but it's possible.

@santigimeno
Copy link
Member

Yeah, I see... still, I think we should not be validating in every invocation when scheduling a job. What about validating in the schedule function, then setting a _do_not_validate property to true. If that property is set we would not validate a RecurrenceRule. When using the RecurrenceRule API this property would not be set and would always be validated.

@santigimeno
Copy link
Member

Still one could abuse the schedule API too, so I don't really know.

@jonhester
Copy link
Contributor Author

@santigimeno Yeah, any way you cut it there is going to have to be a major refactor to fix this the right way. I think your idea is a good compromise to be able to go ahead and implement this. As we are working on the next major version we should make sure we account for this sort of thing.

@jonhester
Copy link
Contributor Author

@santigimeno @tejasmanohar Should we hold this over until the next major version when we can validate in a way that's not a hack, or do you think it's worth implementing in the current version?

@tejasmanohar
Copy link
Member

@jonhester My vote is validate in a way that's not a hack and wait for 1.0. What's yours + @santigimeno? We can just go w/ majority.

@santigimeno
Copy link
Member

Yep. I would wait too

@tejasmanohar
Copy link
Member

Then, we'll re-open this when the time comes?

@jonhester
Copy link
Contributor Author

Yeah, there's no possible way to do it correctly now. But working on this made me a lot more familiar with some of the issues and limitations of the current version so I think it was still worth my time.

Sent from my iPhone

On Mar 21, 2015, at 7:01 PM, Tejas Manohar notifications@github.com wrote:

Closed #122.


Reply to this email directly or view it on GitHub.

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.

None yet

3 participants