Repository navigation
Conversation
Expose a snapshot of a worker's task slot usage per task kind: the number of slots currently marked used, and when a slot was last marked used or a used slot released. Together these let callers tell exactly how long a worker has had no tasks in progress, including tasks that started and finished between two snapshots. The intended first user is idle shutdown in the Lambda worker. Workers implement a separate, optional worker.SlotUsageProvider interface, wrapped by the package-level GetSlotUsage function, so that the worker.Worker interface is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| // NOTE: Experimental | ||
| // | ||
| // Exposed as: [go.temporal.io/sdk/worker.SlotUsage] | ||
| type SlotUsage struct { |
There was a problem hiding this comment.
This API's a bit more general than just a simple combined slot counter, but pretty free given the internal tracking code, and I think maybe more generally useful as a public API.
Sushisource
left a comment
There was a problem hiding this comment.
LGTM but would like @Quinn-With-Two-Ns to sign off too
| // UsedSlotsLastChanged is when a task last started or finished, or the zero time if no task has | ||
| // started since the worker was created. A task that starts and finishes between two snapshots | ||
| // still changes it. | ||
| UsedSlotsLastChanged time.Time |
There was a problem hiding this comment.
Potentially worth discussing if we'd prefer this to be exposed as a time delta (i.e. time.Duration) since the last change, rather than an absolute time. In Go time.Time stores both wall and monotonic time and uses the latter for most difference calculations, but that's not true in other languages so we'd have to worry about exposing wall time vs. monotonic time, and about interactions between the Rust core's time representations and the relevant core-based languages' clocks.
As a public API, absolute time seems more useful than a time delta, so it's what I tentatively went with here.
What was changed
Expose a snapshot of a worker's task slot usage per task kind: the number of slots currently marked used, and when a slot was last marked used or a used slot released. The APIs are experimental.
Workers implement a separate, optional worker.SlotUsageProvider interface, wrapped by the package-level GetSlotUsage function, so that the worker.Worker interface is unchanged.
Why?
This API exposes some task-processing metrics that the default worker mostly already tracks internally through its trackingSlotSupplier. This gives SDK users more visibility into what a worker is doing, such as exactly how long a worker been idle. The intended first user is idle shutdown in the Lambda worker package.
Checklist
How was this tested:
Unit tests added.
Any docs updates needed?
In-repo docs updated.