improvement: Add a jobs and functions package #4
No reviewers
Labels
No labels
🤖 fix nits
🧠 ai fix nits
autorelease
bug
do not merge
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merge when ready
no changelog
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/go-tasks!4
Loading…
Reference in a new issue
No description provided.
Delete branch "ksimons/jobs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Generate changelog in
changelog/@unreleasedType (Select exactly one)
Description Ksimons/jobs
Check the box to generate changelog(s)
✅ Successfully generated changelog entry!
Entry generated via PR title
To modify this entry, edit PR title using proper format.
📋Changelog Preview
💡 Improvements
Thanks! Core functionality looks good.
Most of my feedback is on documentation, although also had a few suggestions/questions about generic type naming and parameter order.
Made suggestions for consideration, but I'm flexible on the specifics.
@ -0,0 +1,50 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.A bit of a nit, but Go 1.9 introduced "type aliases", which use the
=operator (for example,type StringAlias = string), so would avoid using "type alias" as the term here since it's not technically correct.nit, but technically referred to as type conversion in Go rather than type casting.
@ -0,0 +1,42 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.@ -0,0 +1,68 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.Fine to keep this as is if it's already well-established, but for both this function and the next one, it feels more natural to me to have the
function/consumerparameter as the first parameter and theargparameter as the second parameter.Recommending change above --
cseems strange as the name given thatSupplierdoesn't start withc, and for all other arguments in this file we spell them out (consumer,function, etc.) rather than abbreviate, so seems strange to just do that here.Ralso feels more consistent given that for all the other generic functions in this fileTis the input type andRis the return type.@ -0,0 +31,4 @@type NamedRunnable interface {Runnable// Name returns the name for the runnable. A Runnable's name is mostly informational, and generally used to provide a human-readable name for a runnable that can be logged or used for debugging.Name() stringAdded the documentation based on what I believe to be true from seeing uses and thinking about it -- I think it's helpful to clarify. The above also implies that names don't necessarily have to be unique or namespaced (if that is a requirement/consumers are allowed to assume all jobs have unique names, then I think that's something that should be documented).
@ -0,0 +1,56 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.Per question/suggestion above, would it make more sense to have this type be
Rto standardize onRbeing the return type generic name? Could go either way, but that was my thought.(If we go with suggestion of renaming to
R-- otherwise can keep as-is)@ -0,0 +1,41 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.@ -0,0 +28,4 @@// rather than waiting for the first interval to elapse.ShouldStartImmediately(ctx context.Context) bool// GetInterval returns the duration between job executions.GetInterval(ctx context.Context) time.DurationIs there any guidance around expected behavior / general contracts for these functions?
@ -0,0 +37,4 @@type JobRunner interface {// StartJobs begins executing all provided jobs asynchronously.// Each job runs in its own goroutine and will continue until the context is cancelled.StartJobs(ctx context.Context, jobs []Job)Are there any expected behaviors/contracts for this, or is it totally up to the implementor?
@ -0,0 +1,80 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.@ -0,0 +1,58 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.@ -0,0 +1,95 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.Is this something that can be fixed now or is still carried over?
Might be helpful to describe parameter and the general behavior of the default runner (particularly how the provided
KeyedErrorHealthCheckSourceis used?)The parameter is named
k8sKeyedErrorHealthCheckSource-- since the definition here is fairly generic and doesn't otherwise reference/assume k8s, should it just behealthCheckSourceorkeyedErrorHealthCheckSource?Per other comment below, might be better to omit
k8sfrom name for the generic type/struct unless there's a reason that it would always have to be k8s-related@ -0,0 +56,4 @@}// StartJobs starts all of the provided jobs. Creates a new goroutine for each job.func (d defaultJobRunner) StartJobs(ctx context.Context, jobs []Job) {@ -0,0 +28,4 @@// rather than waiting for the first interval to elapse.ShouldStartImmediately(ctx context.Context) bool// GetInterval returns the duration between job executions.GetInterval(ctx context.Context) time.DurationDone
@ -0,0 +1,95 @@// Copyright (c) 2025 Palantir Technologies. All rights reserved.Done