no longer expose the storage task broker
We can implement the task broker completely, so it is not neccessary to export it. This commit also addresses some review comments. Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
@@ -26,7 +26,6 @@ import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
import * as winston from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "InputBase" needs to be exported by the entry point index.d.ts
|
||||
@@ -57,6 +56,9 @@ export class CatalogEntityClient {
|
||||
): Promise<TemplateEntityV1beta2>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type CompletedTaskState = 'failed' | 'completed';
|
||||
|
||||
// Warning: (ae-missing-release-tag) "createBuiltinActions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
@@ -191,11 +193,22 @@ export const createTemplateAction: <
|
||||
templateAction: TemplateAction<Input>,
|
||||
) => TemplateAction<any>;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "CreateWorkerOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export type CreateWorkerOptions = {
|
||||
taskBroker: TaskBroker;
|
||||
actionRegistry: TemplateActionRegistry;
|
||||
integrations: ScmIntegrations;
|
||||
workingDirectory: string;
|
||||
logger: Logger_2;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class DatabaseTaskStore implements TaskStore {
|
||||
constructor(db: Knex);
|
||||
// (undocumented)
|
||||
claimTask(): Promise<DbTaskRow | undefined>;
|
||||
claimTask(): Promise<SerializedTask | undefined>;
|
||||
// (undocumented)
|
||||
completeTask({
|
||||
taskId,
|
||||
@@ -218,14 +231,12 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
// (undocumented)
|
||||
emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
|
||||
// (undocumented)
|
||||
getTask(taskId: string): Promise<DbTaskRow>;
|
||||
getTask(taskId: string): Promise<SerializedTask>;
|
||||
// (undocumented)
|
||||
heartbeatTask(taskId: string): Promise<void>;
|
||||
// Warning: (ae-forgotten-export) The symbol "TaskStoreGetEventsOptions" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// (undocumented)
|
||||
listEvents({ taskId, after }: TaskStoreGetEventsOptions): Promise<{
|
||||
events: DbTaskEventRow[];
|
||||
listEvents({ taskId, after }: TaskStoreListEventsOptions): Promise<{
|
||||
events: SerializedTaskEvent[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
listStaleTasks({ timeoutS }: { timeoutS: number }): Promise<{
|
||||
@@ -235,29 +246,6 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
}>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type DbTaskRow = {
|
||||
id: string;
|
||||
spec: TaskSpec;
|
||||
status: Status;
|
||||
createdAt: string;
|
||||
lastHeartbeatAt?: string;
|
||||
secrets?: TaskSecrets;
|
||||
};
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "WorkflowRunner" needs to be exported by the entry point index.d.ts
|
||||
// Warning: (ae-missing-release-tag) "DefaultWorkflowRunner" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export class DefaultWorkflowRunner implements WorkflowRunner {
|
||||
// Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts
|
||||
constructor(options: Options_3);
|
||||
// Warning: (ae-forgotten-export) The symbol "WorkflowResponse" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// (undocumented)
|
||||
execute(task: Task): Promise<WorkflowResponse>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type DispatchResult = {
|
||||
taskId: string;
|
||||
@@ -280,14 +268,6 @@ export function fetchContents({
|
||||
outputPath: string;
|
||||
}): Promise<void>;
|
||||
|
||||
// @public
|
||||
export class LegacyWorkflowRunner implements WorkflowRunner {
|
||||
// Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts
|
||||
constructor(options: Options_2);
|
||||
// (undocumented)
|
||||
execute(task: Task): Promise<WorkflowResponse>;
|
||||
}
|
||||
|
||||
// Warning: (ae-missing-release-tag) "OctokitProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public
|
||||
@@ -299,17 +279,6 @@ export class OctokitProvider {
|
||||
}
|
||||
|
||||
// @public
|
||||
export type RawDbTaskEventRow = {
|
||||
id: number;
|
||||
task_id: string;
|
||||
body: string;
|
||||
event_type: TaskEventType;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "RouterOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export interface RouterOptions {
|
||||
// (undocumented)
|
||||
actions?: TemplateAction<any>[];
|
||||
@@ -353,6 +322,25 @@ export class ScaffolderEntitiesProcessor implements CatalogProcessor {
|
||||
validateEntityKind(entity: Entity): Promise<boolean>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type SerializedTask = {
|
||||
id: string;
|
||||
spec: TaskSpec;
|
||||
status: Status;
|
||||
createdAt: string;
|
||||
lastHeartbeatAt?: string;
|
||||
secrets?: TaskSecrets;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type SerializedTaskEvent = {
|
||||
id: number;
|
||||
taskId: string;
|
||||
body: JsonObject;
|
||||
type: TaskEventType;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type Status =
|
||||
| 'open'
|
||||
@@ -361,40 +349,8 @@ export type Status =
|
||||
| 'cancelled'
|
||||
| 'completed';
|
||||
|
||||
// @public
|
||||
export class StorageTaskBroker implements TaskBroker {
|
||||
constructor(storage: TaskStore, logger: Logger_2);
|
||||
// (undocumented)
|
||||
claim(): Promise<Task>;
|
||||
// (undocumented)
|
||||
dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
|
||||
// (undocumented)
|
||||
get(taskId: string): Promise<DbTaskRow>;
|
||||
// (undocumented)
|
||||
protected readonly logger: Logger_2;
|
||||
// (undocumented)
|
||||
observe(
|
||||
options: {
|
||||
taskId: string;
|
||||
after: number | undefined;
|
||||
},
|
||||
callback: (
|
||||
error: Error | undefined,
|
||||
result: {
|
||||
events: DbTaskEventRow[];
|
||||
},
|
||||
) => void,
|
||||
): () => void;
|
||||
// (undocumented)
|
||||
protected readonly storage: TaskStore;
|
||||
// (undocumented)
|
||||
vacuumTasks(timeoutS: { timeoutS: number }): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface Task {
|
||||
// Warning: (ae-forgotten-export) The symbol "CompletedTaskState" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// (undocumented)
|
||||
complete(result: CompletedTaskState, metadata?: JsonValue): Promise<void>;
|
||||
// (undocumented)
|
||||
@@ -409,14 +365,10 @@ export interface Task {
|
||||
spec: TaskSpec;
|
||||
}
|
||||
|
||||
// Warning: (ae-missing-release-tag) "TaskAgent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
// @public
|
||||
export class TaskAgent implements Task {
|
||||
// (undocumented)
|
||||
complete(result: CompletedTaskState, metadata?: JsonObject): Promise<void>;
|
||||
// Warning: (ae-forgotten-export) The symbol "TaskState" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// (undocumented)
|
||||
static create(
|
||||
state: TaskState,
|
||||
@@ -440,12 +392,9 @@ export interface TaskBroker {
|
||||
// (undocumented)
|
||||
claim(): Promise<Task>;
|
||||
// (undocumented)
|
||||
dispatch(
|
||||
spec: TaskSpec,
|
||||
secretTaskSecretss?: TaskSecrets,
|
||||
): Promise<DispatchResult>;
|
||||
dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
|
||||
// (undocumented)
|
||||
get(taskId: string): Promise<DbTaskRow>;
|
||||
get(taskId: string): Promise<SerializedTask>;
|
||||
// (undocumented)
|
||||
observe(
|
||||
options: {
|
||||
@@ -455,7 +404,7 @@ export interface TaskBroker {
|
||||
callback: (
|
||||
error: Error | undefined,
|
||||
result: {
|
||||
events: DbTaskEventRow[];
|
||||
events: SerializedTaskEvent[];
|
||||
},
|
||||
) => void,
|
||||
): () => void;
|
||||
@@ -463,9 +412,6 @@ export interface TaskBroker {
|
||||
vacuumTasks(timeoutS: { timeoutS: number }): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type TaskEventType = 'completion' | 'log';
|
||||
|
||||
// @public
|
||||
export type TaskSecrets = {
|
||||
token: string | undefined;
|
||||
@@ -514,10 +460,20 @@ export interface TaskSpecV1beta3 {
|
||||
steps: TaskStep[];
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface TaskState {
|
||||
// (undocumented)
|
||||
secrets?: TaskSecrets;
|
||||
// (undocumented)
|
||||
spec: TaskSpec;
|
||||
// (undocumented)
|
||||
taskId: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface TaskStore {
|
||||
// (undocumented)
|
||||
claimTask(): Promise<DbTaskRow | undefined>;
|
||||
claimTask(): Promise<SerializedTask | undefined>;
|
||||
// (undocumented)
|
||||
completeTask(options: {
|
||||
taskId: string;
|
||||
@@ -534,12 +490,12 @@ export interface TaskStore {
|
||||
// (undocumented)
|
||||
emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
|
||||
// (undocumented)
|
||||
getTask(taskId: string): Promise<DbTaskRow>;
|
||||
getTask(taskId: string): Promise<SerializedTask>;
|
||||
// (undocumented)
|
||||
heartbeatTask(taskId: string): Promise<void>;
|
||||
// (undocumented)
|
||||
listEvents({ taskId, after }: TaskStoreGetEventsOptions): Promise<{
|
||||
events: DbTaskEventRow[];
|
||||
listEvents({ taskId, after }: TaskStoreListEventsOptions): Promise<{
|
||||
events: SerializedTaskEvent[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
listStaleTasks(options: { timeoutS: number }): Promise<{
|
||||
@@ -555,16 +511,32 @@ export type TaskStoreEmitOptions = {
|
||||
body: JsonObject;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type TaskStoreListEventsOptions = {
|
||||
taskId: string;
|
||||
after?: number | undefined;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class TaskWorker {
|
||||
// Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts
|
||||
constructor(options: Options);
|
||||
constructor(options: TaskWorkerOptions);
|
||||
// (undocumented)
|
||||
static createWorker(options: CreateWorkerOptions): TaskWorker;
|
||||
// (undocumented)
|
||||
runOneTask(task: Task): Promise<void>;
|
||||
// (undocumented)
|
||||
start(): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type TaskWorkerOptions = {
|
||||
taskBroker: TaskBroker;
|
||||
runners: {
|
||||
legacyWorkflowRunner: LegacyWorkflowRunner;
|
||||
workflowRunner: WorkflowRunner;
|
||||
};
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "TemplateAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
@@ -594,5 +566,7 @@ export class TemplateActionRegistry {
|
||||
|
||||
// Warnings were encountered during analysis:
|
||||
//
|
||||
// src/scaffolder/tasks/DatabaseTaskStore.d.ts:51:9 - (ae-forgotten-export) The symbol "DbTaskEventRow" needs to be exported by the entry point index.d.ts
|
||||
// src/scaffolder/tasks/TaskWorker.d.ts:14:9 - (ae-forgotten-export) The symbol "LegacyWorkflowRunner" needs to be exported by the entry point index.d.ts
|
||||
// src/scaffolder/tasks/TaskWorker.d.ts:15:9 - (ae-forgotten-export) The symbol "WorkflowRunner" needs to be exported by the entry point index.d.ts
|
||||
// src/scaffolder/tasks/types.d.ts:37:5 - (ae-forgotten-export) The symbol "TaskEventType" needs to be exported by the entry point index.d.ts
|
||||
```
|
||||
|
||||
@@ -24,3 +24,10 @@ export * from './scaffolder';
|
||||
export * from './service/router';
|
||||
export * from './lib/catalog';
|
||||
export * from './processor';
|
||||
export { TaskAgent } from './scaffolder/tasks';
|
||||
export type {
|
||||
TaskBroker,
|
||||
DispatchResult,
|
||||
TaskStore,
|
||||
Task,
|
||||
} from './scaffolder/tasks/types';
|
||||
|
||||
@@ -14,27 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
export * from './actions';
|
||||
export {
|
||||
TaskAgent,
|
||||
DatabaseTaskStore,
|
||||
StorageTaskBroker,
|
||||
TaskWorker,
|
||||
LegacyWorkflowRunner,
|
||||
DefaultWorkflowRunner,
|
||||
} from './tasks';
|
||||
export { DatabaseTaskStore, TaskWorker } from './tasks';
|
||||
export type { TaskWorkerOptions, CreateWorkerOptions } from './tasks';
|
||||
export type { TaskState } from './tasks';
|
||||
export type {
|
||||
Task,
|
||||
TaskBroker,
|
||||
TaskSpec,
|
||||
TaskSecrets,
|
||||
DispatchResult,
|
||||
TaskStore,
|
||||
TaskSpec,
|
||||
CompletedTaskState,
|
||||
TaskStoreEmitOptions,
|
||||
DbTaskRow,
|
||||
TaskStoreListEventsOptions,
|
||||
SerializedTask,
|
||||
SerializedTaskEvent,
|
||||
TaskSpecV1beta2,
|
||||
TaskSpecV1beta3,
|
||||
Status,
|
||||
TaskEventType,
|
||||
} from './tasks/types';
|
||||
|
||||
export type { RawDbTaskEventRow } from './tasks/DatabaseTaskStore';
|
||||
|
||||
@@ -20,15 +20,15 @@ import { ConflictError, NotFoundError } from '@backstage/errors';
|
||||
import { Knex } from 'knex';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import {
|
||||
DbTaskEventRow,
|
||||
DbTaskRow,
|
||||
SerializedTaskEvent,
|
||||
SerializedTask,
|
||||
Status,
|
||||
TaskEventType,
|
||||
TaskSecrets,
|
||||
TaskSpec,
|
||||
TaskStore,
|
||||
TaskStoreEmitOptions,
|
||||
TaskStoreGetEventsOptions,
|
||||
TaskStoreListEventsOptions,
|
||||
} from './types';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
@@ -46,10 +46,6 @@ export type RawDbTaskRow = {
|
||||
secrets?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* RawDbTaskEventRow
|
||||
* @public
|
||||
*/
|
||||
export type RawDbTaskEventRow = {
|
||||
id: number;
|
||||
task_id: string;
|
||||
@@ -60,6 +56,7 @@ export type RawDbTaskEventRow = {
|
||||
|
||||
/**
|
||||
* DatabaseTaskStore
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class DatabaseTaskStore implements TaskStore {
|
||||
@@ -72,7 +69,7 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
|
||||
constructor(private readonly db: Knex) {}
|
||||
|
||||
async getTask(taskId: string): Promise<DbTaskRow> {
|
||||
async getTask(taskId: string): Promise<SerializedTask> {
|
||||
const [result] = await this.db<RawDbTaskRow>('tasks')
|
||||
.where({ id: taskId })
|
||||
.select();
|
||||
@@ -109,7 +106,7 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
return { taskId };
|
||||
}
|
||||
|
||||
async claimTask(): Promise<DbTaskRow | undefined> {
|
||||
async claimTask(): Promise<SerializedTask | undefined> {
|
||||
return this.db.transaction(async tx => {
|
||||
const [task] = await tx<RawDbTaskRow>('tasks')
|
||||
.where({
|
||||
@@ -251,7 +248,7 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
async listEvents({
|
||||
taskId,
|
||||
after,
|
||||
}: TaskStoreGetEventsOptions): Promise<{ events: DbTaskEventRow[] }> {
|
||||
}: TaskStoreListEventsOptions): Promise<{ events: SerializedTaskEvent[] }> {
|
||||
const rawEvents = await this.db<RawDbTaskEventRow>('task_events')
|
||||
.where({
|
||||
task_id: taskId,
|
||||
|
||||
@@ -34,7 +34,7 @@ import { validate as validateJsonSchema } from 'jsonschema';
|
||||
import { parseRepoUrl } from '../actions/builtin/publish/util';
|
||||
import { TemplateActionRegistry } from '../actions';
|
||||
|
||||
type Options = {
|
||||
type NunjucksWorkflowRunnerOptions = {
|
||||
workingDirectory: string;
|
||||
actionRegistry: TemplateActionRegistry;
|
||||
integrations: ScmIntegrations;
|
||||
@@ -77,10 +77,6 @@ const createStepLogger = ({ task, step }: { task: Task; step: TaskStep }) => {
|
||||
return { taskLogger, streamLogger };
|
||||
};
|
||||
|
||||
/*
|
||||
* DefaultWorkflowRunner
|
||||
* @public
|
||||
*/
|
||||
export class DefaultWorkflowRunner implements WorkflowRunner {
|
||||
private readonly nunjucks: nunjucks.Environment;
|
||||
|
||||
@@ -92,7 +88,7 @@ export class DefaultWorkflowRunner implements WorkflowRunner {
|
||||
},
|
||||
};
|
||||
|
||||
constructor(private readonly options: Options) {
|
||||
constructor(private readonly options: NunjucksWorkflowRunnerOptions) {
|
||||
this.nunjucks = nunjucks.configure(this.nunjucksOptions);
|
||||
|
||||
// TODO(blam): let's work out how we can deprecate these.
|
||||
|
||||
@@ -43,13 +43,9 @@ type Options = {
|
||||
|
||||
const isValidTaskSpec = (taskSpec: TaskSpec): taskSpec is TaskSpecV1beta2 =>
|
||||
taskSpec.apiVersion === 'backstage.io/v1beta2';
|
||||
|
||||
/**
|
||||
* This is the legacy workflow runner, which supports handlebars. This entire implementation will be replaced
|
||||
* with the default workflow runner interface in the future so this entire thing can go bye bye.
|
||||
*
|
||||
* LegacyWorkflowRunner
|
||||
* @public
|
||||
*/
|
||||
export class LegacyWorkflowRunner implements WorkflowRunner {
|
||||
private readonly handlebars: typeof Handlebars;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { getVoidLogger, DatabaseManager } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { DatabaseTaskStore } from './DatabaseTaskStore';
|
||||
import { StorageTaskBroker, TaskAgent } from './StorageTaskBroker';
|
||||
import { TaskSecrets, TaskSpec, DbTaskEventRow } from './types';
|
||||
import { TaskSecrets, TaskSpec, SerializedTaskEvent } from './types';
|
||||
|
||||
async function createStore(): Promise<DatabaseTaskStore> {
|
||||
const manager = DatabaseManager.fromConfig(
|
||||
@@ -127,8 +127,8 @@ describe('StorageTaskBroker', () => {
|
||||
|
||||
const { taskId } = await broker1.dispatch({} as TaskSpec);
|
||||
|
||||
const logPromise = new Promise<DbTaskEventRow[]>(resolve => {
|
||||
const observedEvents = new Array<DbTaskEventRow>();
|
||||
const logPromise = new Promise<SerializedTaskEvent[]>(resolve => {
|
||||
const observedEvents = new Array<SerializedTaskEvent>();
|
||||
|
||||
broker2.observe({ taskId, after: undefined }, (_err, { events }) => {
|
||||
observedEvents.push(...events);
|
||||
|
||||
@@ -23,11 +23,13 @@ import {
|
||||
TaskStore,
|
||||
TaskBroker,
|
||||
DispatchResult,
|
||||
DbTaskEventRow,
|
||||
DbTaskRow,
|
||||
SerializedTaskEvent,
|
||||
SerializedTask,
|
||||
} from './types';
|
||||
|
||||
/*
|
||||
/**
|
||||
* TaskAgent
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class TaskAgent implements Task {
|
||||
@@ -106,7 +108,12 @@ export class TaskAgent implements Task {
|
||||
}
|
||||
}
|
||||
|
||||
interface TaskState {
|
||||
/**
|
||||
* TaskState
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TaskState {
|
||||
spec: TaskSpec;
|
||||
taskId: string;
|
||||
secrets?: TaskSecrets;
|
||||
@@ -120,14 +127,10 @@ function defer() {
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
/**
|
||||
* StorageTaskBroker
|
||||
* @public
|
||||
*/
|
||||
export class StorageTaskBroker implements TaskBroker {
|
||||
constructor(
|
||||
protected readonly storage: TaskStore,
|
||||
protected readonly logger: Logger,
|
||||
private readonly storage: TaskStore,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
private deferredDispatch = defer();
|
||||
|
||||
@@ -161,7 +164,7 @@ export class StorageTaskBroker implements TaskBroker {
|
||||
};
|
||||
}
|
||||
|
||||
async get(taskId: string): Promise<DbTaskRow> {
|
||||
async get(taskId: string): Promise<SerializedTask> {
|
||||
return this.storage.getTask(taskId);
|
||||
}
|
||||
|
||||
@@ -172,7 +175,7 @@ export class StorageTaskBroker implements TaskBroker {
|
||||
},
|
||||
callback: (
|
||||
error: Error | undefined,
|
||||
result: { events: DbTaskEventRow[] },
|
||||
result: { events: SerializedTaskEvent[] },
|
||||
) => void,
|
||||
): () => void {
|
||||
const { taskId } = options;
|
||||
|
||||
@@ -13,10 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Task, TaskBroker, WorkflowRunner } from './types';
|
||||
import { LegacyWorkflowRunner } from './LegacyWorkflowRunner';
|
||||
import { DefaultWorkflowRunner } from './DefaultWorkflowRunner';
|
||||
import { Logger } from 'winston';
|
||||
import { TemplateActionRegistry } from '../actions';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
|
||||
type Options = {
|
||||
/**
|
||||
* TaskWorkerOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskWorkerOptions = {
|
||||
taskBroker: TaskBroker;
|
||||
runners: {
|
||||
legacyWorkflowRunner: LegacyWorkflowRunner;
|
||||
@@ -24,12 +34,56 @@ type Options = {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* CreateWorkerOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CreateWorkerOptions = {
|
||||
taskBroker: TaskBroker;
|
||||
actionRegistry: TemplateActionRegistry;
|
||||
integrations: ScmIntegrations;
|
||||
workingDirectory: string;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
/**
|
||||
* TaskWorker
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class TaskWorker {
|
||||
constructor(private readonly options: Options) {}
|
||||
constructor(private readonly options: TaskWorkerOptions) {}
|
||||
|
||||
static createWorker(options: CreateWorkerOptions) {
|
||||
const {
|
||||
taskBroker,
|
||||
logger,
|
||||
actionRegistry,
|
||||
integrations,
|
||||
workingDirectory,
|
||||
} = options;
|
||||
|
||||
const legacyWorkflowRunner = new LegacyWorkflowRunner({
|
||||
logger,
|
||||
actionRegistry,
|
||||
integrations,
|
||||
workingDirectory,
|
||||
});
|
||||
|
||||
const workflowRunner = new DefaultWorkflowRunner({
|
||||
actionRegistry,
|
||||
integrations,
|
||||
logger,
|
||||
workingDirectory,
|
||||
});
|
||||
|
||||
return new TaskWorker({
|
||||
taskBroker: taskBroker,
|
||||
runners: { legacyWorkflowRunner, workflowRunner },
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
(async () => {
|
||||
for (;;) {
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
export { DatabaseTaskStore } from './DatabaseTaskStore';
|
||||
export { StorageTaskBroker, TaskAgent } from './StorageTaskBroker';
|
||||
export type { TaskState } from './StorageTaskBroker';
|
||||
export { TaskWorker } from './TaskWorker';
|
||||
export { LegacyWorkflowRunner } from './LegacyWorkflowRunner';
|
||||
export { DefaultWorkflowRunner } from './DefaultWorkflowRunner';
|
||||
export type { TaskWorkerOptions, CreateWorkerOptions } from './TaskWorker';
|
||||
|
||||
@@ -18,6 +18,7 @@ import { JsonValue, JsonObject } from '@backstage/config';
|
||||
|
||||
/**
|
||||
* Status
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type Status =
|
||||
@@ -27,13 +28,19 @@ export type Status =
|
||||
| 'cancelled'
|
||||
| 'completed';
|
||||
|
||||
/**
|
||||
* CompletedTaskState
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CompletedTaskState = 'failed' | 'completed';
|
||||
|
||||
/**
|
||||
* DbTaskRow
|
||||
* SerializedTask
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type DbTaskRow = {
|
||||
export type SerializedTask = {
|
||||
id: string;
|
||||
spec: TaskSpec;
|
||||
status: Status;
|
||||
@@ -42,17 +49,14 @@ export type DbTaskRow = {
|
||||
secrets?: TaskSecrets;
|
||||
};
|
||||
|
||||
/**
|
||||
* TaskEventType
|
||||
* @public
|
||||
*/
|
||||
export type TaskEventType = 'completion' | 'log';
|
||||
|
||||
/**
|
||||
* DbTaskEventRow
|
||||
* SerializedTaskEvent
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type DbTaskEventRow = {
|
||||
export type SerializedTaskEvent = {
|
||||
id: number;
|
||||
taskId: string;
|
||||
body: JsonObject;
|
||||
@@ -62,6 +66,7 @@ export type DbTaskEventRow = {
|
||||
|
||||
/**
|
||||
* TaskSpecV1beta2
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TaskSpecV1beta2 {
|
||||
@@ -88,6 +93,7 @@ export interface TaskStep {
|
||||
|
||||
/**
|
||||
* TaskSpecV1beta3
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TaskSpecV1beta3 {
|
||||
@@ -100,12 +106,14 @@ export interface TaskSpecV1beta3 {
|
||||
|
||||
/**
|
||||
* TaskSpec
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;
|
||||
|
||||
/**
|
||||
* TaskSecrets
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskSecrets = {
|
||||
@@ -114,6 +122,7 @@ export type TaskSecrets = {
|
||||
|
||||
/**
|
||||
* DispatchResult
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type DispatchResult = {
|
||||
@@ -122,6 +131,7 @@ export type DispatchResult = {
|
||||
|
||||
/**
|
||||
* Task
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface Task {
|
||||
@@ -135,14 +145,12 @@ export interface Task {
|
||||
|
||||
/**
|
||||
* TaskBroker
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TaskBroker {
|
||||
claim(): Promise<Task>;
|
||||
dispatch(
|
||||
spec: TaskSpec,
|
||||
secretTaskSecretss?: TaskSecrets,
|
||||
): Promise<DispatchResult>;
|
||||
dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
|
||||
vacuumTasks(timeoutS: { timeoutS: number }): Promise<void>;
|
||||
observe(
|
||||
options: {
|
||||
@@ -151,15 +159,15 @@ export interface TaskBroker {
|
||||
},
|
||||
callback: (
|
||||
error: Error | undefined,
|
||||
result: { events: DbTaskEventRow[] },
|
||||
result: { events: SerializedTaskEvent[] },
|
||||
) => void,
|
||||
): () => void;
|
||||
|
||||
get(taskId: string): Promise<DbTaskRow>;
|
||||
get(taskId: string): Promise<SerializedTask>;
|
||||
}
|
||||
|
||||
/**
|
||||
* TaskStoreEmitOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskStoreEmitOptions = {
|
||||
@@ -167,13 +175,19 @@ export type TaskStoreEmitOptions = {
|
||||
body: JsonObject;
|
||||
};
|
||||
|
||||
export type TaskStoreGetEventsOptions = {
|
||||
/**
|
||||
* TaskStoreListEventsOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskStoreListEventsOptions = {
|
||||
taskId: string;
|
||||
after?: number | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* TaskStore
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface TaskStore {
|
||||
@@ -181,8 +195,8 @@ export interface TaskStore {
|
||||
task: TaskSpec,
|
||||
secrets?: TaskSecrets,
|
||||
): Promise<{ taskId: string }>;
|
||||
getTask(taskId: string): Promise<DbTaskRow>;
|
||||
claimTask(): Promise<DbTaskRow | undefined>;
|
||||
getTask(taskId: string): Promise<SerializedTask>;
|
||||
claimTask(): Promise<SerializedTask | undefined>;
|
||||
completeTask(options: {
|
||||
taskId: string;
|
||||
status: Status;
|
||||
@@ -197,14 +211,10 @@ export interface TaskStore {
|
||||
listEvents({
|
||||
taskId,
|
||||
after,
|
||||
}: TaskStoreGetEventsOptions): Promise<{ events: DbTaskEventRow[] }>;
|
||||
}: TaskStoreListEventsOptions): Promise<{ events: SerializedTaskEvent[] }>;
|
||||
}
|
||||
|
||||
export type WorkflowResponse = { output: { [key: string]: JsonValue } };
|
||||
/*
|
||||
* WorkflowRunner
|
||||
* @public
|
||||
*/
|
||||
export interface WorkflowRunner {
|
||||
execute(task: Task): Promise<WorkflowResponse>;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
TaskWorker,
|
||||
} from '../scaffolder/tasks';
|
||||
import { TemplateActionRegistry } from '../scaffolder/actions/TemplateActionRegistry';
|
||||
import { TaskBroker } from '../scaffolder';
|
||||
import { getEntityBaseUrl, getWorkingDirectory } from './helpers';
|
||||
import {
|
||||
ContainerRunner,
|
||||
@@ -41,11 +40,15 @@ import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { TemplateAction } from '../scaffolder/actions';
|
||||
import { createBuiltinActions } from '../scaffolder/actions/builtin/createBuiltinActions';
|
||||
|
||||
import { LegacyWorkflowRunner } from '../scaffolder/tasks/LegacyWorkflowRunner';
|
||||
import { DefaultWorkflowRunner } from '../scaffolder/tasks/DefaultWorkflowRunner';
|
||||
import { TaskSpec } from '../scaffolder/tasks/types';
|
||||
import { TaskBroker, TaskSpec } from '../scaffolder/tasks/types';
|
||||
|
||||
/**
|
||||
* RouterOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface RouterOptions {
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
|
||||
Reference in New Issue
Block a user