Skip to content

Commit

Permalink
fix: add polling lifecycle events
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Nov 14, 2024
1 parent 3fc0db2 commit 695fd08
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/agentTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Connection, PollingClient, StatusResult } from '@salesforce/core';
import { Connection, Lifecycle, PollingClient, StatusResult } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { MaybeMock } from './maybe-mock';

Expand Down Expand Up @@ -71,13 +71,16 @@ export class AgentTester {
timeout: Duration.minutes(5),
}
): Promise<{ response: AgentTestDetailsResponse; formatted: string }> {
const lifecycle = Lifecycle.getInstance();
const client = await PollingClient.create({
poll: async (): Promise<StatusResult> => {
const { status } = await this.status(jobId);
if (status === 'COMPLETED') {
await lifecycle.emit('AGENT_TEST_POLLING_EVENT', { jobId, status });
return { payload: await this.details(jobId, format), completed: true };
}

await lifecycle.emit('AGENT_TEST_POLLING_EVENT', { jobId, status });
return { completed: false };
},
frequency: Duration.seconds(1),
Expand Down

0 comments on commit 695fd08

Please sign in to comment.