-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow storing arbitrary data in a job #124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than 1 nit
@levb Heads up that I added some thoughts about using generics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just one nit below. I'd also want @cpoile to take a look, since he worked on this initially and he'll have the best context to review the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting! I think we might need to think a second though before merging, just in case --
For a bit of context -- the reason we didn't include a props in the first version of this was that the key the job returns can be the key in the kvstore -- so if you want to store a "props" you would store them in the kvstore with that key and pull it out once the jobonce fires. Which means less data trapped in goroutines...
This PR might let people think they can put anything into Props
, which could cause some problems if they do put anything in there...
Also, I haven't looked at Go generics yet, but do we have a way (e.g., type bounds?) to ensure that Props
is json.Marshal
and json.Unmarshal
-able?
It's worth noting that the KV store methods like Line 58 in 24f6408
Given that
I can't think of a way. Generics in go don't allow recursive type parameters. Hence, |
True, but I think the real issue is whether we want to put big chunks of data in the job once goroutines. This was meant to be lightweight. The way it's designed now, there can be an unlimited number of long running goroutines parked waiting for their timer to expire. If we really want to attach data to the job once items, I think we need to redesign how the system schedules and parks its future events. I think @lieut-data had a good idea: we could use a priority queue and periodically poll the db to add soon-to-fire items to that queue. That way we would have only the next x minutes of items parked at any one time. If we moved to something like that, I think there might be less chance for memory issues when users store arbitrary amounts of data. Or, alternatively, set a max number of bytes and enforce that at runtime? |
/update-branch |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 72.82% 73.13% +0.30%
==========================================
Files 33 33
Lines 1774 1783 +9
==========================================
+ Hits 1292 1304 +12
+ Misses 418 416 -2
+ Partials 64 63 -1
☔ View full report in Codecov by Sentry. |
@cpoile A priority queue is an awesome idea to reduce the memory consumption of the job scheduler. But it's a bit out of scope of this PR. I think it would make for a great HW ticket! As part of this PR I've added a limit of 10k bytes for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I think that's a reasonable compromise since parked routines are about 4k.
I really hope people don't fill these props up though, that would have unexpected results if they don't understand what's really happening (every one is parked until it runs).
Co-authored-by: Christopher Poile <[email protected]>
Summary
This PR allows plugins to store arbitrary data as part of their scheduled jobs.
props
is stored as part of theJobOnce
struct in the KV store.I tried implementing the changes using generics for type safety, but that didn't work out well with the current way the code is structured, as
JobOnceScheduler
is a global singleton.The code should look like this:
which doesn't work as
JobOnceScheduler[T]
can't be assigned to aJobOnceScheduler[any]
.If this PR needs type safety, which would be nice, we would need to get rid of the singleton. That could be done by prefixing the key of each scheduler, a pattern that is used in other packages of
pluginapi
.Ticket Link
Needed for mattermost/mattermost-plugin-apps#375