mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix component metadata
This commit is contained in:
@@ -27,7 +27,7 @@ export default class Queue {
|
||||
options?: {
|
||||
scheduleAt?: string;
|
||||
}
|
||||
) {
|
||||
): Promise<void> {
|
||||
const optionsObject: JobsOptions = {
|
||||
jobId: jobId.toString(),
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ export default class QueueWorker {
|
||||
queueName: QueueName,
|
||||
onJobInQueue: (job: QueueJob) => Promise<void>,
|
||||
options: { concurrency: number }
|
||||
) {
|
||||
): Worker {
|
||||
return new Worker(queueName, onJobInQueue, {
|
||||
connection: {
|
||||
host: RedisHostname.toString(),
|
||||
|
||||
@@ -33,7 +33,7 @@ export class Service extends DatabaseService<Model> {
|
||||
for (const node of ((onUpdate.updateBy.data as any).graph as any)[
|
||||
'nodes'
|
||||
] as Array<JSONObject>) {
|
||||
const nodeData = node['data'] as NodeDataProp;
|
||||
const nodeData: NodeDataProp = node['data'] as NodeDataProp;
|
||||
if (
|
||||
nodeData.componentType === ComponentType.Trigger &&
|
||||
nodeData.nodeType === NodeType.Node
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import { JSONArray, JSONObject } from 'Common/Types/JSON';
|
||||
import { JSONArray, JSONObject, JSONValue } from 'Common/Types/JSON';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import ComponentMetadata, { Port } from 'Common/Types/Workflow/Component';
|
||||
import { ExpressRouter } from '../../Utils/Express';
|
||||
@@ -36,11 +36,11 @@ export interface InitProps {
|
||||
|
||||
export default class ComponentCode {
|
||||
private metadata: ComponentMetadata | null = null;
|
||||
private logs: Array<string> = [];
|
||||
protected logs: Array<string> = [];
|
||||
|
||||
public constructor() {}
|
||||
|
||||
public setMetadata(metadata: ComponentMetadata) {
|
||||
public setMetadata(metadata: ComponentMetadata): void {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export default class ComponentCode {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
public log(data: string | JSONObject | JSONArray) {
|
||||
public log(data: string | JSONObject | JSONArray | JSONValue): void {
|
||||
if (typeof data === 'string') {
|
||||
this.logs.push(
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() + ':' + data
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import { JSONObject } from 'Common/Types/JSON';
|
||||
import ComponentMetadata, { Port } from 'Common/Types/Workflow/Component';
|
||||
import ComponentID from 'Common/Types/Workflow/ComponentID';
|
||||
import WebhookComponents from 'Common/Types/Workflow/Components/Webhook';
|
||||
import ComponentCode, { RunProps, RunReturnType } from '../ComponentCode';
|
||||
import ComponentCode, { RunReturnType } from '../ComponentCode';
|
||||
|
||||
export default class Log extends ComponentCode {
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
const LogComponent: ComponentMetadata | undefined =
|
||||
WebhookComponents.find((i: ComponentMetadata) => {
|
||||
return i.id === ComponentID.Log;
|
||||
@@ -15,12 +18,13 @@ export default class Log extends ComponentCode {
|
||||
if (!LogComponent) {
|
||||
throw new BadDataException('Component not found.');
|
||||
}
|
||||
super(LogComponent);
|
||||
|
||||
this.setMetadata(LogComponent);
|
||||
}
|
||||
|
||||
public override run(props: RunProps): Promise<RunReturnType> {
|
||||
public override run(args: JSONObject): Promise<RunReturnType> {
|
||||
const outPort: Port | undefined = this.getMetadata().outPorts.find(
|
||||
(p) => {
|
||||
(p: Port) => {
|
||||
return p.id === 'out';
|
||||
}
|
||||
);
|
||||
@@ -29,12 +33,13 @@ export default class Log extends ComponentCode {
|
||||
throw new BadDataException('Out port not found');
|
||||
}
|
||||
|
||||
console.log(OneUptimeDate.getCurrentDateAsFormattedString() + ':');
|
||||
console.log(props.arguments['value']);
|
||||
this.log(OneUptimeDate.getCurrentDateAsFormattedString() + ':');
|
||||
this.log(args['value']);
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: {},
|
||||
executePort: outPort,
|
||||
logs: this.logs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import ComponentCode, {
|
||||
|
||||
export default class WebhookTrigger extends ComponentCode {
|
||||
public constructor() {
|
||||
super();
|
||||
const WebhookComponent: ComponentMetadata | undefined =
|
||||
WebhookComponents.find((i: ComponentMetadata) => {
|
||||
return i.id === ComponentID.Webhook;
|
||||
@@ -20,7 +21,7 @@ export default class WebhookTrigger extends ComponentCode {
|
||||
if (!WebhookComponent) {
|
||||
throw new BadDataException('Webhook trigger not found.');
|
||||
}
|
||||
super(WebhookComponent);
|
||||
this.setMetadata(WebhookComponent);
|
||||
}
|
||||
|
||||
public override async init(props: InitProps): Promise<void> {
|
||||
@@ -43,7 +44,7 @@ export default class WebhookTrigger extends ComponentCode {
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
props: InitProps
|
||||
) {
|
||||
): Promise<void> {
|
||||
/// Run Graph.
|
||||
|
||||
const executeWorkflow: ExecuteWorkflowType = {
|
||||
|
||||
@@ -27,11 +27,12 @@ import Button, { ButtonStyleType } from 'CommonUI/src/Components/Button/Button';
|
||||
import ComponentLoader from 'CommonUI/src/Components/ComponentLoader/ComponentLoader';
|
||||
import IconProp from 'Common/Types/Icon/IconProp';
|
||||
import { loadComponentsAndCategories } from 'CommonUI/src/Components/Workflow/Utils';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import ComponentMetadata, {
|
||||
NodeDataProp,
|
||||
NodeType,
|
||||
ComponentCategory,
|
||||
} from 'Common/Types/Workflow/Component';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import { NodeDataProp, NodeType } from 'Common/Types/Workflow/Component';
|
||||
|
||||
const Delete: FunctionComponent<PageComponentProps> = (
|
||||
_props: PageComponentProps
|
||||
|
||||
@@ -4,6 +4,7 @@ import ComponentCode, {
|
||||
ExecuteWorkflowType,
|
||||
} from 'CommonServer/Types/Workflow/ComponentCode';
|
||||
import QueueWorkflow from '../Services/QueueWorkflow';
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
|
||||
export default class ComponentCodeAPI {
|
||||
public router!: ExpressRouter;
|
||||
@@ -17,12 +18,16 @@ export default class ComponentCodeAPI {
|
||||
const ComponentCodeItem: typeof ComponentCode | undefined =
|
||||
Components[key];
|
||||
if (ComponentCodeItem) {
|
||||
const instance = new ComponentCodeItem();
|
||||
instance.init({
|
||||
router: this.router,
|
||||
scheduleWorkflow: this.scheduleWorkflow,
|
||||
executeWorkflow: this.executeWorkflow,
|
||||
});
|
||||
const instance: ComponentCode = new ComponentCodeItem();
|
||||
instance
|
||||
.init({
|
||||
router: this.router,
|
||||
scheduleWorkflow: this.scheduleWorkflow,
|
||||
executeWorkflow: this.executeWorkflow,
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
logger.error(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,12 +35,14 @@ export default class ComponentCodeAPI {
|
||||
public async scheduleWorkflow(
|
||||
executeWorkflow: ExecuteWorkflowType,
|
||||
scheduleAt: string
|
||||
) {
|
||||
): Promise<void> {
|
||||
/// add to queue.
|
||||
await QueueWorkflow.addWorkflowToQueue(executeWorkflow, scheduleAt);
|
||||
}
|
||||
|
||||
public async executeWorkflow(executeWorkflow: ExecuteWorkflowType) {
|
||||
public async executeWorkflow(
|
||||
executeWorkflow: ExecuteWorkflowType
|
||||
): Promise<void> {
|
||||
// add to queue.
|
||||
await QueueWorkflow.addWorkflowToQueue(executeWorkflow);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export default class ManualAPI {
|
||||
public async manuallyRunWorkflow(
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse
|
||||
) {
|
||||
): Promise<void> {
|
||||
// add this workflow to the run queue and return the 200 response.
|
||||
|
||||
if (!req.params['workflowId']) {
|
||||
|
||||
@@ -22,7 +22,7 @@ app.use(`/manual`, new ManualAPI().router);
|
||||
QueueWorker.getWorker(
|
||||
QueueName.Workflow,
|
||||
async (job: QueueJob) => {
|
||||
new RunWorkflow().runWorkflow({
|
||||
await new RunWorkflow().runWorkflow({
|
||||
workflowId: new ObjectID(job.data['workflowId'] as string),
|
||||
workflowLogId: new ObjectID(job.data['workflowLogId'] as string),
|
||||
arguments: job.data.data as JSONObject,
|
||||
|
||||
@@ -14,7 +14,7 @@ export default class QueueWorkflow {
|
||||
executeWorkflow: ExecuteWorkflowType,
|
||||
scheduleAt?: string
|
||||
): Promise<void> {
|
||||
const workflowId = executeWorkflow.workflowId;
|
||||
const workflowId: ObjectID = executeWorkflow.workflowId;
|
||||
|
||||
// get workflow to see if its enabled.
|
||||
const workflow: Workflow | null = await WorkflowService.findOneById({
|
||||
@@ -44,7 +44,7 @@ export default class QueueWorkflow {
|
||||
|
||||
// Add Workflow Run Log.
|
||||
|
||||
const runLog = new WorkflowLog();
|
||||
const runLog: WorkflowLog = new WorkflowLog();
|
||||
runLog.workflowId = workflowId;
|
||||
runLog.projectId = workflow.projectId;
|
||||
runLog.workflowStatus = WorkflowStatus.Scheduled;
|
||||
@@ -52,7 +52,7 @@ export default class QueueWorkflow {
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
': Workflow Scheduled.';
|
||||
|
||||
const created = await WorkflowLogService.create({
|
||||
const created: WorkflowLog = await WorkflowLogService.create({
|
||||
data: runLog,
|
||||
props: {
|
||||
isRoot: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Dictionary from 'Common/Types/Dictionary';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import { JSONArray, JSONObject } from 'Common/Types/JSON';
|
||||
import { JSONArray, JSONObject, JSONValue } from 'Common/Types/JSON';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import ComponentMetadata, {
|
||||
ComponentType,
|
||||
@@ -23,6 +23,7 @@ import WorkflowStatus from 'Common/Types/Workflow/WorkflowStatus';
|
||||
import Components from 'CommonServer/Types/Workflow/Components/Index';
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
import { loadAllComponentMetadata } from '../Utils/ComponentMetadata';
|
||||
import Workflow from 'Model/Models/Workflow';
|
||||
|
||||
const AllComponents: Dictionary<ComponentMetadata> = loadAllComponentMetadata();
|
||||
|
||||
@@ -56,7 +57,7 @@ export default class RunWorkflow {
|
||||
public async runWorkflow(runProps: RunProps): Promise<void> {
|
||||
// get nodes and edges.
|
||||
|
||||
const workflow = await WorkflowService.findOneById({
|
||||
const workflow: Workflow | null = await WorkflowService.findOneById({
|
||||
id: runProps.workflowId,
|
||||
select: {
|
||||
graph: true,
|
||||
@@ -225,13 +226,15 @@ export default class RunWorkflow {
|
||||
continue;
|
||||
}
|
||||
|
||||
let argumentContent = component.arguments[argument.id];
|
||||
let argumentContent: JSONValue | undefined =
|
||||
component.arguments[argument.id];
|
||||
|
||||
if (!argumentContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof argumentContent === 'string' &&
|
||||
argumentContent.toString().includes('{{') &&
|
||||
argumentContent.toString().includes('}}')
|
||||
) {
|
||||
@@ -260,7 +263,7 @@ export default class RunWorkflow {
|
||||
Components[node.metadata.id];
|
||||
|
||||
if (ComponentCodeItem) {
|
||||
const instance = new ComponentCodeItem();
|
||||
const instance: ComponentCode = new ComponentCodeItem();
|
||||
return await instance.run({
|
||||
arguments: args,
|
||||
});
|
||||
@@ -334,7 +337,7 @@ export default class RunWorkflow {
|
||||
return newStorageMap;
|
||||
}
|
||||
|
||||
public log(data: string | JSONObject | JSONArray) {
|
||||
public log(data: string | JSONObject | JSONArray): void {
|
||||
if (typeof data === 'string') {
|
||||
this.logs.push(
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() + ':' + data
|
||||
@@ -402,7 +405,7 @@ export default class RunWorkflow {
|
||||
item.outPorts[edge['sourceHandle']] = [];
|
||||
}
|
||||
|
||||
const connectedNode = nodes.find((n: any) => {
|
||||
const connectedNode: any = nodes.find((n: any) => {
|
||||
return n.id === edge.target;
|
||||
});
|
||||
|
||||
@@ -416,7 +419,7 @@ export default class RunWorkflow {
|
||||
runStackItems[node.data.id] = item;
|
||||
}
|
||||
|
||||
const trigger: any | undefined = nodes.find((n) => {
|
||||
const trigger: any | undefined = nodes.find((n: any) => {
|
||||
return (
|
||||
(n.data as NodeDataProp).componentType ===
|
||||
ComponentType.Trigger &&
|
||||
|
||||
@@ -13,7 +13,7 @@ export const loadAllComponentMetadata: Function =
|
||||
}
|
||||
|
||||
for (const model of Entities) {
|
||||
const baseModelComponentMetadata =
|
||||
const baseModelComponentMetadata: Array<ComponentMetadata> =
|
||||
BaseModelComponentFactory.getComponents(new model());
|
||||
|
||||
for (const componentMetadata of baseModelComponentMetadata) {
|
||||
|
||||
Reference in New Issue
Block a user