-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
every()
funcs final implementation
#98
Conversation
I haven't reviewed this yet, but deleting |
hmmm, i understand what you are talking about. BUT For the record i tried to not remove |
I agree with @0xTim - I haven't reviewed this yet but we definitely can't merge anything that would break the public API since we can't guarantee that no one is using it |
You both are not wrong, again. What i'm trying to say is that this is worth it although there is a 1/100 chance that this might be breaking. So here are possibilities i can think of that one would suffer from // Explicit `: ScheduleBuilder`?!
let builder: ScheduleBuilder = app.queues.schedule(JOB())
builder.minutely().at(5) They'll need to replace let minute: ScheduleBuilder.Minute = 5 They'll need to replace The question that remains is that do you guys think those are enough reasons to delay these changes to a major version? All those being said, the way the I respect you two's decision if you think this PR is still not appropriate for a minor-version. I'll wait for you to review the code and notify me of your decision; or ask any questions if you have. |
Unfortunately breaking the public API under any circumstance is not possible for a non-major release. Getting build errors when running package updates destroys trust in the ecosystem so we can't allow it. However, if there is no reasonable way to get this in with a non-breaking change we could release a major version with it in. There's nothing saying we can't release a major version update tomorrow |
So lesson 1 learned ✅: No breaking API changes in minor versions! About releasing a major version, i think we'll need to know what @jdmcd thinks. I personally have no problem with that, and think this is a good point to start improving the package both because its been stale for a while now and because i believe something like this PR does remove some obstacles which are in the way of this package getting better. |
This probably shouldn't stay opened. It's breaking and if we were to publish a new major version, we can do better than this. |
Intro Notes
What does this PR add to the queues package?
This PR adds the ability to schedule a
ScheduledJob
to be run at different times in any interval. For example you can call the.every(_:in:)
functions like so.every(.seconds(5), in: .minutes(1))
and expect the schedule to be run every 5 seconds in a minute, indefinitely.Motivation
I've not only seen other people be looking for such option in a long time, but i myself have been looking forward to having such options as well. I also saw the open issue here on github, and saw tanner suggesting the syntax
.every
for a function which allows people do the same thing that i implemented. That led me to think about contributing to the package by implementing this feature myself.What exactly is implemented?
.every(_:in:underestimatedCount:)
to be able to flexibly schedule a task to be done every while in an interval. This function is declared in the classScheduleContainer.Builder
, which is the equivalent to theScheduleBuilder
class prior to this PR. Thisevery
function is declared inScheduleContainer
as well for more convenience.Secondly
,Minutely
andHourly
to schedule a task every input amount of times in those types' respective intervals.How was this implementations made possible?
When we want to schedule a job, we need to do like so:
app.queues.schedule(ScheduledJob())
which prior to this PR, would return a class
ScheduleBuilder
. We then can add time specifications tothe builder using the available functions like
.at(Date())
or.minutely().at(5)
. The first problem in the wayof implementing
.every
functions is that a builder is supposed to only contain one job and one time, and theScheduleBuilder
neither can contain more than one time for a job, nor can produce more schedules of its own kind which have different times than itself. To fix this, i came up with 2-3 different ways, and chose the one that you see. I decided to make a change as described below:ScheduleContainer
so it can contain more than one builder.ScheduleContainer
instead of the builder when users doapp.queues.schedule(_:)
What
ScheduleContainer
does is to hold multiple values ofScheduleContainer.Builder
, plus the job that the buildersare supposed to be scheduled with. So you'll see this in declaration of
ScheduleContainer
:I also changed
Builder
a little bit to hold a reference to its container, as well as using uuid to be able to identify buildersthat are in a container:
I also changed the way that a builder holds the time that it should be scheduled at, by introducing an enum:
TimeValue:
Now a builder can clean-ly hold its time. This also helps when calculating the
nextDate
.Another also, i declared convenience functions on top of
ScheduleContainer
which also avoids breaking people's codes.So as an example, the first function is in
Builder
, and the second one is inScheduleContainer
:One thing remaining, is that now that we have containers, one problem appears. The problem is that when we call
app.queues.schedule(JOB())
, theAnyScheduledJob
s must not be immediately created. Instead, they should be created after the user is done with adding their builders to the container. If the app tries to createAnyScheduledJob
s out of a container's job and builders immediately after the.schedule(_:)
call happens, when it checks for builders, it'll see an empty array and basically no jobs will be added to theQueuesConfiguration
. To tackle this i changed the scheduler to store all containers, and only calculateAnyScheduledJob
s when needed:This is the summary of what i've done. You can dig into the files more, and i've left some comments there as well. Feel free to ask any questions you might have, or point out any issues with this implementation.
My questions
These are basically the more-important things that i think i could improve:
ScheduleContainer.swift
line 338, IsunderestimatedCount
justified?.every
func always start from the current time. I don't think thats an issue, but what are your opinions?@discardableResult
behind the declarations of the.minutely
function. I removed that since i couldn't figure out why it was there. Was that a mistake?