Implement cancelTask in MockSchedulerService with proper error types
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
@@ -643,6 +643,7 @@ export interface RootServiceFactoryOptions<
|
||||
|
||||
// @public
|
||||
export interface SchedulerService {
|
||||
cancelTask(id: string): Promise<void>;
|
||||
createScheduledTaskRunner(
|
||||
schedule: SchedulerServiceTaskScheduleDefinition,
|
||||
): SchedulerServiceTaskRunner;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
SchedulerServiceTaskRunner,
|
||||
SchedulerServiceTaskScheduleDefinition,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ConflictError, NotFoundError } from '@backstage/errors';
|
||||
import { createDeferred, DeferredPromise } from '@backstage/types';
|
||||
|
||||
export class MockSchedulerService implements SchedulerService {
|
||||
@@ -95,14 +96,21 @@ export class MockSchedulerService implements SchedulerService {
|
||||
});
|
||||
}
|
||||
|
||||
async cancelTask(_id: string): Promise<void> {
|
||||
// No-op in mock
|
||||
async cancelTask(id: string): Promise<void> {
|
||||
const task = this.#tasks.get(id);
|
||||
if (!task) {
|
||||
throw new NotFoundError(`Task ${id} not found`);
|
||||
}
|
||||
if (!this.#runningTasks.has(id)) {
|
||||
throw new ConflictError(`Task ${id} is not running`);
|
||||
}
|
||||
task.abortControllers.abort();
|
||||
}
|
||||
|
||||
async triggerTask(id: string): Promise<void> {
|
||||
const task = this.#tasks.get(id);
|
||||
if (!task) {
|
||||
throw new Error(`Task ${id} not found`);
|
||||
throw new NotFoundError(`Task ${id} not found`);
|
||||
}
|
||||
if (this.#runningTasks.has(id)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user