Repository navigation
Commit 4961fc4
feat(sdk,core,webapp): key each concurrency limit separately with an object concurrencyKey
## Summary
`concurrencyKey` now also takes an object, so one run can be limited by
two limits keyed by different things, for example a cap per session and
a cap per organization. A string key works exactly as before.
```ts
export const orgLimit = concurrencyLimit({ name: "org-subagents", perKey: 20 });
export const subagent = task({
id: "subagent",
// 3 per session, 200 in total, plus the org limit
concurrency: [{ perKey: 3, total: 200 }, orgLimit],
run: async () => {},
});
await subagent.trigger(payload, {
concurrencyKey: {
default: sessionId,
[orgLimit.name]: orgId,
},
});
```
A limit uses its own entry if it has one, otherwise `default`. A string
is shorthand for `{ default: string }`.
## Design
`default` stays the run's own key, so the run is still queued and
scheduled per default key and everything that reads a run's
`concurrencyKey` still sees a string. Each other entry gives the named
limit of that name its own key. The run queue already supports a key per
limit, so there is no engine change.
- `default` is required in the object form. Without it every run would
wait in one unkeyed queue, where one key at its cap can hold up the keys
behind it.
- An entry for a limit the task does not declare adds that limit to the
run, so triggers keep working while a deploy that adds the limit is
still rolling out. A name that matches no declared limit caps nothing,
and the limit that was meant falls back to `default`.
- A server without this change rejects the object form instead of
mis-keying the limits.
- A run holds at most four limits, counting the task's inline limit and
any added by an entry.
Mono-RevId: 41d8c74aee7609f5f5c88ec33076504f7c4f3e281 parent 4302c02 commit 4961fc4
17 files changed
Lines changed: 506 additions & 38 deletions
File tree
- .changeset
- apps/webapp
- app/runEngine
- concerns
- services
- test/engine
- docs
- internal-packages/run-engine/src/run-queue/tests
- packages
- core/src/v3
- isomorphic
- schemas
- types
- react-hooks/src/hooks
- trigger-sdk/src/v3
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
270 | 302 | | |
271 | | - | |
272 | | - | |
| 303 | + | |
| 304 | + | |
273 | 305 | | |
274 | 306 | | |
275 | 307 | | |
276 | | - | |