@brandboostinggmbh/observable-workflows 0.15.5 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -0
- package/dist/index.js +52 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -462,6 +462,23 @@ declare const createLogAccessor: (context: {
|
|
|
462
462
|
getWorkflowTypesByTenantId: (tenantId: string) => Promise<string[]>;
|
|
463
463
|
getWorkflowByTriggerId: (triggerId: string) => Promise<WorkflowRun | null>;
|
|
464
464
|
getPropertiesKeys: (instanceId?: string) => Promise<WorkflowPropertyDefinition[]>;
|
|
465
|
+
getWorkflowTypesStatistics: ({
|
|
466
|
+
tenantId,
|
|
467
|
+
fromTime,
|
|
468
|
+
toTime
|
|
469
|
+
}: {
|
|
470
|
+
/** override the tenantId */
|
|
471
|
+
tenantId?: string;
|
|
472
|
+
/** Milliseconds since epoch */
|
|
473
|
+
fromTime?: number;
|
|
474
|
+
/** Milliseconds since epoch */
|
|
475
|
+
toTime?: number;
|
|
476
|
+
}) => Promise<{
|
|
477
|
+
workflowType: string;
|
|
478
|
+
workflowCount: number;
|
|
479
|
+
workflowTotalWallTimeMilis: number;
|
|
480
|
+
incompleteWorkflowCount: number;
|
|
481
|
+
}[]>;
|
|
465
482
|
};
|
|
466
483
|
|
|
467
484
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -243,6 +243,7 @@ async function createIndexes(db) {
|
|
|
243
243
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_status ON WorkflowTable (workflowStatus)`).run();
|
|
244
244
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_steps_instance_id ON StepTable (instanceId)`).run();
|
|
245
245
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_steps_tenant_id ON StepTable (tenantId)`).run();
|
|
246
|
+
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_steps_start_time ON StepTable (startTime)`).run();
|
|
246
247
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_logs_instance_id ON LogTable (instanceId)`).run();
|
|
247
248
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_logs_tenant_id ON LogTable (tenantId)`).run();
|
|
248
249
|
await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflow_properties_tenant_id ON WorkflowProperties (tenantId)`).run();
|
|
@@ -921,6 +922,55 @@ const createLogAccessor = (context) => {
|
|
|
921
922
|
valueType: row.valueType
|
|
922
923
|
}));
|
|
923
924
|
};
|
|
925
|
+
const getWorkflowTypesStatistics = async ({ tenantId, fromTime, toTime }) => {
|
|
926
|
+
const whereConditions = [];
|
|
927
|
+
const bindings = [];
|
|
928
|
+
const actualTenantId = tenantId || context.tenantId;
|
|
929
|
+
whereConditions.push("tenantId = ?");
|
|
930
|
+
bindings.push(actualTenantId);
|
|
931
|
+
if (fromTime !== void 0) {
|
|
932
|
+
whereConditions.push("startTime >= ?");
|
|
933
|
+
bindings.push(fromTime);
|
|
934
|
+
}
|
|
935
|
+
if (toTime !== void 0) {
|
|
936
|
+
whereConditions.push("startTime <= ?");
|
|
937
|
+
bindings.push(toTime);
|
|
938
|
+
}
|
|
939
|
+
const whereClause = whereConditions.length > 0 ? `WHERE ${whereConditions.join(" AND ")}` : "";
|
|
940
|
+
const result = await context.D1.prepare(
|
|
941
|
+
/* sql */
|
|
942
|
+
`
|
|
943
|
+
SELECT
|
|
944
|
+
workflowType,
|
|
945
|
+
COUNT(*) as workflowCount,
|
|
946
|
+
SUM(
|
|
947
|
+
CASE
|
|
948
|
+
WHEN endTime IS NOT NULL AND startTime IS NOT NULL
|
|
949
|
+
THEN (endTime - startTime)
|
|
950
|
+
ELSE 0
|
|
951
|
+
END
|
|
952
|
+
) as workflowTotalWallTimeMilis,
|
|
953
|
+
SUM(
|
|
954
|
+
CASE
|
|
955
|
+
WHEN startTime IS NOT NULL AND endTime IS NULL
|
|
956
|
+
THEN 1
|
|
957
|
+
ELSE 0
|
|
958
|
+
END
|
|
959
|
+
) as incompleteWorkflowCount
|
|
960
|
+
FROM WorkflowTable
|
|
961
|
+
${whereClause}
|
|
962
|
+
GROUP BY workflowType
|
|
963
|
+
ORDER BY workflowCount DESC
|
|
964
|
+
`
|
|
965
|
+
).bind(...bindings).all();
|
|
966
|
+
if (!result.results) return [];
|
|
967
|
+
return result.results.map((row) => ({
|
|
968
|
+
workflowType: row.workflowType,
|
|
969
|
+
workflowCount: row.workflowCount,
|
|
970
|
+
workflowTotalWallTimeMilis: row.workflowTotalWallTimeMilis || 0,
|
|
971
|
+
incompleteWorkflowCount: row.incompleteWorkflowCount || 0
|
|
972
|
+
}));
|
|
973
|
+
};
|
|
924
974
|
return {
|
|
925
975
|
listSteps,
|
|
926
976
|
getStep,
|
|
@@ -928,7 +978,8 @@ const createLogAccessor = (context) => {
|
|
|
928
978
|
getWorkflow,
|
|
929
979
|
getWorkflowTypesByTenantId,
|
|
930
980
|
getWorkflowByTriggerId,
|
|
931
|
-
getPropertiesKeys
|
|
981
|
+
getPropertiesKeys,
|
|
982
|
+
getWorkflowTypesStatistics
|
|
932
983
|
};
|
|
933
984
|
};
|
|
934
985
|
|