added long-running action and example template
Signed-off-by: Hao Luo <howlowck@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ metadata:
|
||||
spec:
|
||||
targets:
|
||||
- ./remote-templates.yaml
|
||||
- ./longrunning-demo/wait-action.yaml
|
||||
# For local development of a template, you can reference your local templates here.
|
||||
# Examples:
|
||||
#
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
apiVersion: scaffolder.backstage.io/v1beta3
|
||||
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-template
|
||||
kind: Template
|
||||
metadata:
|
||||
name: wait-action
|
||||
title: wait-action
|
||||
description: template with a waiting task for a long running action
|
||||
spec:
|
||||
owner: user:guest
|
||||
type: service
|
||||
|
||||
# These parameters are used to generate the input form in the frontend, and are
|
||||
# used to gather input data for the execution of the template.
|
||||
parameters:
|
||||
- title: Fill in some steps
|
||||
required:
|
||||
- name
|
||||
properties:
|
||||
name:
|
||||
title: Name
|
||||
type: string
|
||||
description: Unique name of the component
|
||||
default: some value
|
||||
ui:autofocus: true
|
||||
ui:options:
|
||||
rows: 5
|
||||
|
||||
# These steps are executed in the scaffolder backend, using data that we gathered
|
||||
# via the parameters above.
|
||||
steps:
|
||||
- id: someAsyncCall
|
||||
name: Some Async Call
|
||||
action: debug:log
|
||||
input:
|
||||
message: Some async call that return a tickedId (guid, for instance, that identifies a process)
|
||||
|
||||
- id: waitWorkflow
|
||||
name: Wait Creation
|
||||
action: stress:waitWorkflow
|
||||
input:
|
||||
name: 'test' #${{ steps.someAsyncCall.output.ticketId }}
|
||||
delayMilliseconds: 1000
|
||||
maxCalls: 30
|
||||
@@ -55,6 +55,7 @@ import {
|
||||
createPublishGitlabAction,
|
||||
createPublishGitlabMergeRequestAction,
|
||||
} from './publish';
|
||||
import { waitWorkflow } from './stress';
|
||||
|
||||
/**
|
||||
* The options passed to {@link createBuiltinActions}
|
||||
@@ -181,6 +182,7 @@ export const createBuiltinActions = (
|
||||
config,
|
||||
githubCredentialsProvider,
|
||||
}),
|
||||
waitWorkflow(),
|
||||
];
|
||||
|
||||
return actions as TemplateAction<JsonObject>[];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { waitWorkflow } from './waitWorkflow';
|
||||
@@ -0,0 +1,86 @@
|
||||
import { createTemplateAction } from '@backstage/plugin-scaffolder-backend';
|
||||
|
||||
export function waitWorkflow() {
|
||||
type InputParameters = {
|
||||
name: string;
|
||||
delayMilliseconds: number;
|
||||
maxCalls: number;
|
||||
};
|
||||
|
||||
return createTemplateAction<InputParameters>({
|
||||
id: 'stress:waitWorkflow',
|
||||
schema: {
|
||||
input: {
|
||||
required: ['name'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
title: 'Name',
|
||||
description:
|
||||
'The Ticket Number used to check the status of the Workflow.',
|
||||
},
|
||||
delayMilliseconds: {
|
||||
type: 'number',
|
||||
title: 'Delay',
|
||||
description:
|
||||
'The amount of milliseconds to delay before the next checkStatus call.',
|
||||
},
|
||||
maxCalls: {
|
||||
type: 'number',
|
||||
title: 'Max Calls',
|
||||
description:
|
||||
'The amount of maximum calls allowed to check a status before stopping.',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
status: {
|
||||
title: 'Status',
|
||||
type: 'object',
|
||||
properties: {
|
||||
message: {
|
||||
title: 'Status Message',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
results: {
|
||||
title: 'Results from Ticket execution',
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async handler(ctx) {
|
||||
const { name, maxCalls, delayMilliseconds } = getParameters(ctx.input);
|
||||
|
||||
ctx.logger.info(`Running the long running workflow: ${name}...`);
|
||||
|
||||
let i = 1;
|
||||
|
||||
for (;;) {
|
||||
ctx.logger.info(`waiting... [${i}/${maxCalls}]`);
|
||||
|
||||
if (i++ >= maxCalls) {
|
||||
break;
|
||||
}
|
||||
|
||||
await new Promise(res => setTimeout(res, delayMilliseconds));
|
||||
}
|
||||
|
||||
ctx.output('status.message', 'Workflow completed');
|
||||
},
|
||||
});
|
||||
|
||||
function getParameters(input: InputParameters) {
|
||||
const { name, delayMilliseconds, maxCalls } = input;
|
||||
return {
|
||||
name,
|
||||
maxCalls: maxCalls ?? 30,
|
||||
delayMilliseconds: delayMilliseconds ?? 2000,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user