Skip to content

Commit c93fcc8

Browse files
committed
add support for event summary
Signed-off-by: Kent Rancourt <[email protected]>
1 parent 18e22de commit c93fcc8

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/core/events.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ export interface Event {
102102
* that are useful only to properly configured Workers.
103103
*/
104104
payload?: string
105+
/**
106+
* A counterpart to payload. If payload is free-form Worker input,
107+
* then Summary is free-form Worker output. It can optionally be set by a
108+
* Worker to provide a summary of the work completed by the Worker and its
109+
* Jobs.
110+
*/
111+
summary?: string
105112
/**
106113
* Contains details of the Worker assigned to handle the Event
107114
*/
@@ -119,6 +126,16 @@ export interface SourceState {
119126
state?: { [key: string]: string }
120127
}
121128

129+
/**
130+
* Encapsulates an opaque, Worker-specific summary of an Event.
131+
*/
132+
export interface EventSummary {
133+
/**
134+
* The Event summary as (optionally) provided by a Worker.
135+
*/
136+
text: string
137+
}
138+
122139
/**
123140
* Useful filter criteria when selecting multiple Events for API group
124141
* operations like list, cancel, or delete.
@@ -281,6 +298,19 @@ export class EventsClient {
281298
return this.rmClient.executeRequest(req) as Promise<Event>
282299
}
283300

301+
/**
302+
* Updates a Worker-specific Event summary.
303+
*
304+
* @param id Identifier of the Event to update
305+
* @throws An error if the specified Event is not found
306+
*/
307+
public async updateSummary(id: string, summary: EventSummary): Promise<void> {
308+
const req = new rm.Request("PUT", `v2/events/${id}/summary`)
309+
req.bodyObj = summary
310+
req.successCode = 200
311+
return this.rmClient.executeRequest(req) as Promise<void>
312+
}
313+
284314
/**
285315
* Copies an Event in a terminal state, including Worker configuration and
286316
* creates a new Event from this information. Where possible, job results are

test/core/events.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CancelManyEventsResult, DeleteManyEventsResult, Event, EventsClient } from "../../src/core/events"
1+
import { CancelManyEventsResult, DeleteManyEventsResult, Event, EventsClient, EventSummary } from "../../src/core/events"
22
import { WorkerPhase } from "../../src/core/workers"
33
import * as meta from "../../src/meta"
44

@@ -158,6 +158,23 @@ describe("events", () => {
158158
})
159159
})
160160

161+
describe("#updateSummary", () => {
162+
it("should send/receive properly over HTTP", async () => {
163+
const testEventID = "12345"
164+
const testSummary: EventSummary = {
165+
text: "This is a summary"
166+
}
167+
await common.testClient({
168+
expectedRequestMethod: "PUT",
169+
expectedRequestPath: `/v2/events/${testEventID}/summary`,
170+
expectedRequestBody: testSummary,
171+
clientInvocationLogic: () => {
172+
return client.updateSummary(testEventID, testSummary)
173+
}
174+
})
175+
})
176+
})
177+
161178
describe("#retry", () => {
162179
it("should send/receive properly over HTTP", async () => {
163180
const testOriginalEventID = "tunguska"

0 commit comments

Comments
 (0)