@cadenza.io/service 1.25.8 → 1.26.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.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +348 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -149
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ declare class DeputyTask extends Task {
|
|
|
13
13
|
readonly isDeputy: boolean;
|
|
14
14
|
protected readonly remoteRoutineName: string;
|
|
15
15
|
protected serviceName: string | undefined;
|
|
16
|
+
registeredDeputyMap: boolean;
|
|
16
17
|
/**
|
|
17
18
|
* Constructs a new instance of the class with the specified parameters.
|
|
18
19
|
*
|
|
@@ -331,6 +332,7 @@ interface TableDefinition {
|
|
|
331
332
|
[key in DbOperationType]?: (string | {
|
|
332
333
|
signal: string;
|
|
333
334
|
condition?: (ctx: AnyObject) => boolean;
|
|
335
|
+
queryData?: DbOperationPayload;
|
|
334
336
|
})[];
|
|
335
337
|
};
|
|
336
338
|
emissions?: {
|
|
@@ -21974,6 +21976,8 @@ declare class CadenzaService {
|
|
|
21974
21976
|
* ```
|
|
21975
21977
|
*/
|
|
21976
21978
|
static run(task: Task | GraphRoutine, context: AnyObject): void;
|
|
21979
|
+
static schedule(taskName: string, context: AnyObject, timeoutMs: number, exactDateTime?: Date): void;
|
|
21980
|
+
static throttle(taskName: string, context: AnyObject, intervalMs: number, leading?: boolean, startDateTime?: Date): void;
|
|
21977
21981
|
/**
|
|
21978
21982
|
* Logs a message with a specified log level and additional contextual data.
|
|
21979
21983
|
* Records in the CadenzaDB when available.
|
|
@@ -21986,6 +21990,7 @@ declare class CadenzaService {
|
|
|
21986
21990
|
* @return {void} No return value.
|
|
21987
21991
|
*/
|
|
21988
21992
|
static log(message: string, data?: any, level?: "info" | "warning" | "error" | "critical", subjectServiceName?: string | null, subjectServiceInstanceId?: string | null): void;
|
|
21993
|
+
static get(taskName: string): Task | undefined;
|
|
21989
21994
|
/**
|
|
21990
21995
|
* Creates a new DeputyTask instance based on the provided routine name, service name, and options.
|
|
21991
21996
|
* This method ensures proper task initialization, including setting a unique name,
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare class DeputyTask extends Task {
|
|
|
13
13
|
readonly isDeputy: boolean;
|
|
14
14
|
protected readonly remoteRoutineName: string;
|
|
15
15
|
protected serviceName: string | undefined;
|
|
16
|
+
registeredDeputyMap: boolean;
|
|
16
17
|
/**
|
|
17
18
|
* Constructs a new instance of the class with the specified parameters.
|
|
18
19
|
*
|
|
@@ -331,6 +332,7 @@ interface TableDefinition {
|
|
|
331
332
|
[key in DbOperationType]?: (string | {
|
|
332
333
|
signal: string;
|
|
333
334
|
condition?: (ctx: AnyObject) => boolean;
|
|
335
|
+
queryData?: DbOperationPayload;
|
|
334
336
|
})[];
|
|
335
337
|
};
|
|
336
338
|
emissions?: {
|
|
@@ -21974,6 +21976,8 @@ declare class CadenzaService {
|
|
|
21974
21976
|
* ```
|
|
21975
21977
|
*/
|
|
21976
21978
|
static run(task: Task | GraphRoutine, context: AnyObject): void;
|
|
21979
|
+
static schedule(taskName: string, context: AnyObject, timeoutMs: number, exactDateTime?: Date): void;
|
|
21980
|
+
static throttle(taskName: string, context: AnyObject, intervalMs: number, leading?: boolean, startDateTime?: Date): void;
|
|
21977
21981
|
/**
|
|
21978
21982
|
* Logs a message with a specified log level and additional contextual data.
|
|
21979
21983
|
* Records in the CadenzaDB when available.
|
|
@@ -21986,6 +21990,7 @@ declare class CadenzaService {
|
|
|
21986
21990
|
* @return {void} No return value.
|
|
21987
21991
|
*/
|
|
21988
21992
|
static log(message: string, data?: any, level?: "info" | "warning" | "error" | "critical", subjectServiceName?: string | null, subjectServiceInstanceId?: string | null): void;
|
|
21993
|
+
static get(taskName: string): Task | undefined;
|
|
21989
21994
|
/**
|
|
21990
21995
|
* Creates a new DeputyTask instance based on the provided routine name, service name, and options.
|
|
21991
21996
|
* This method ensures proper task initialization, including setting a unique name,
|
package/dist/index.js
CHANGED
|
@@ -153,6 +153,7 @@ var DeputyTask = class extends import_core.Task {
|
|
|
153
153
|
retryDelayFactor
|
|
154
154
|
);
|
|
155
155
|
this.isDeputy = true;
|
|
156
|
+
this.registeredDeputyMap = false;
|
|
156
157
|
this.remoteRoutineName = remoteRoutineName;
|
|
157
158
|
this.serviceName = serviceName;
|
|
158
159
|
this.emit("meta.deputy.created", {
|
|
@@ -524,12 +525,21 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
524
525
|
"Split service instances",
|
|
525
526
|
function* (ctx) {
|
|
526
527
|
const { serviceInstances } = ctx;
|
|
527
|
-
if (!serviceInstances)
|
|
528
|
+
if (!serviceInstances) {
|
|
529
|
+
CadenzaService.log(
|
|
530
|
+
"SyncFailed: No service instances found",
|
|
531
|
+
ctx,
|
|
532
|
+
"error"
|
|
533
|
+
);
|
|
534
|
+
}
|
|
528
535
|
for (const serviceInstance of serviceInstances) {
|
|
529
536
|
yield { serviceInstance };
|
|
530
537
|
}
|
|
531
538
|
}
|
|
532
|
-
).then(this.handleInstanceUpdateTask)
|
|
539
|
+
).then(this.handleInstanceUpdateTask).doOn(
|
|
540
|
+
"meta.cadenza_db.gathered_sync_data",
|
|
541
|
+
"CadenzaDB.meta.cadenza_db.gathered_sync_data"
|
|
542
|
+
)
|
|
533
543
|
);
|
|
534
544
|
this.getInstanceById = CadenzaService.createMetaTask(
|
|
535
545
|
"Get instance by id",
|
|
@@ -3693,15 +3703,39 @@ var DatabaseController = class _DatabaseController {
|
|
|
3693
3703
|
CadenzaService.createThrottledTask(
|
|
3694
3704
|
taskName,
|
|
3695
3705
|
async (context, emit) => {
|
|
3696
|
-
const
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3706
|
+
for (const action of Object.keys(table.customSignals?.triggers ?? {})) {
|
|
3707
|
+
const triggerConditions = (
|
|
3708
|
+
// @ts-ignore
|
|
3709
|
+
table.customSignals?.triggers?.[action].filter(
|
|
3710
|
+
(trigger) => trigger.condition
|
|
3711
|
+
)
|
|
3712
|
+
);
|
|
3713
|
+
for (const triggerCondition of triggerConditions ?? []) {
|
|
3714
|
+
if (triggerCondition.condition && !triggerCondition.condition(context)) {
|
|
3715
|
+
return {
|
|
3716
|
+
failed: true,
|
|
3717
|
+
error: `Condition for signal trigger failed: ${triggerCondition.signal}`
|
|
3718
|
+
};
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
const triggerQueryData = (
|
|
3722
|
+
// @ts-ignore
|
|
3723
|
+
table.customSignals?.triggers?.[action].filter(
|
|
3724
|
+
(trigger) => trigger.queryData
|
|
3725
|
+
)
|
|
3726
|
+
);
|
|
3727
|
+
for (const queryData of triggerQueryData ?? []) {
|
|
3728
|
+
if (context.queryData) {
|
|
3729
|
+
context.queryData = {
|
|
3730
|
+
...context.queryData,
|
|
3731
|
+
...queryData
|
|
3732
|
+
};
|
|
3733
|
+
} else {
|
|
3734
|
+
context = {
|
|
3735
|
+
...context,
|
|
3736
|
+
...queryData
|
|
3737
|
+
};
|
|
3738
|
+
}
|
|
3705
3739
|
}
|
|
3706
3740
|
}
|
|
3707
3741
|
try {
|
|
@@ -3785,175 +3819,284 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
3785
3819
|
return this._instance;
|
|
3786
3820
|
}
|
|
3787
3821
|
constructor() {
|
|
3788
|
-
CadenzaService.
|
|
3789
|
-
"
|
|
3790
|
-
() =>
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3822
|
+
this.splitRoutinesTask = CadenzaService.createMetaTask(
|
|
3823
|
+
"Split routines for registration",
|
|
3824
|
+
(ctx, emit) => {
|
|
3825
|
+
const { __routines } = ctx;
|
|
3826
|
+
if (!__routines) return;
|
|
3827
|
+
for (const routine of __routines) {
|
|
3828
|
+
if (routine.registered) continue;
|
|
3829
|
+
routine.registered = true;
|
|
3830
|
+
emit("meta.sync_controller.routine_added", {
|
|
3831
|
+
data: {
|
|
3832
|
+
name: routine.name,
|
|
3833
|
+
version: routine.version,
|
|
3834
|
+
description: routine.description,
|
|
3835
|
+
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
3836
|
+
isMeta: routine.isMeta
|
|
3837
|
+
}
|
|
3838
|
+
});
|
|
3839
|
+
for (const task of routine.tasks) {
|
|
3840
|
+
const tasks = task.getIterator();
|
|
3841
|
+
while (tasks.hasNext()) {
|
|
3842
|
+
const nextTask = tasks.next();
|
|
3843
|
+
emit("meta.sync_controller.task_to_routine_map", {
|
|
3844
|
+
data: {
|
|
3845
|
+
taskName: nextTask.name,
|
|
3846
|
+
taskVersion: nextTask.version,
|
|
3847
|
+
routineName: routine.name,
|
|
3848
|
+
routineVersion: routine.version,
|
|
3849
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3850
|
+
}
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
emit("meta.sync_controller.synced", {
|
|
3805
3856
|
data: {
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3857
|
+
is_active: true,
|
|
3858
|
+
is_non_responsive: false,
|
|
3859
|
+
is_blocked: false,
|
|
3860
|
+
last_active: formatTimestamp(Date.now())
|
|
3861
|
+
},
|
|
3862
|
+
filter: {
|
|
3863
|
+
uuid: CadenzaService.serviceRegistry.serviceInstanceId
|
|
3811
3864
|
}
|
|
3812
3865
|
});
|
|
3813
|
-
|
|
3814
|
-
const tasks = task.getIterator();
|
|
3815
|
-
while (tasks.hasNext()) {
|
|
3816
|
-
const nextTask = tasks.next();
|
|
3817
|
-
emit("meta.sync_controller.task_to_routine_map", {
|
|
3818
|
-
data: {
|
|
3819
|
-
taskName: nextTask.name,
|
|
3820
|
-
taskVersion: nextTask.version,
|
|
3821
|
-
routineName: routine.name,
|
|
3822
|
-
routineVersion: routine.version,
|
|
3823
|
-
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3824
|
-
}
|
|
3825
|
-
});
|
|
3826
|
-
}
|
|
3827
|
-
}
|
|
3866
|
+
CadenzaService.log("Synced data...");
|
|
3828
3867
|
}
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3868
|
+
);
|
|
3869
|
+
this.splitSignalsTask = CadenzaService.createMetaTask(
|
|
3870
|
+
"Split signals for registration",
|
|
3871
|
+
function* (ctx, emit) {
|
|
3872
|
+
const { __signals } = ctx;
|
|
3873
|
+
if (!__signals) return;
|
|
3874
|
+
const filteredSignals = __signals.filter(
|
|
3875
|
+
(signal) => !signal.data.registered
|
|
3876
|
+
).map((signal) => signal.signal);
|
|
3877
|
+
for (const signal of filteredSignals) {
|
|
3878
|
+
const { isMeta, sourceServiceName, domain, action } = decomposeSignalName(signal);
|
|
3879
|
+
yield {
|
|
3880
|
+
data: {
|
|
3881
|
+
name: signal,
|
|
3882
|
+
sourceServiceName,
|
|
3883
|
+
domain,
|
|
3884
|
+
action,
|
|
3885
|
+
isMeta,
|
|
3886
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3887
|
+
}
|
|
3888
|
+
};
|
|
3838
3889
|
}
|
|
3839
|
-
}
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
(signal) => !signal.data.registered
|
|
3847
|
-
).map((signal) => signal.signal);
|
|
3848
|
-
for (const signal of filteredSignals) {
|
|
3849
|
-
const { isMeta, sourceServiceName, domain, action } = decomposeSignalName(signal);
|
|
3850
|
-
emit("meta.sync_controller.signal_added", {
|
|
3851
|
-
data: {
|
|
3852
|
-
name: signal,
|
|
3853
|
-
sourceServiceName,
|
|
3854
|
-
domain,
|
|
3855
|
-
action,
|
|
3856
|
-
isMeta,
|
|
3857
|
-
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3890
|
+
}
|
|
3891
|
+
).doAfter(CadenzaService.broker.getSignalsTask).then(
|
|
3892
|
+
CadenzaService.createCadenzaDBInsertTask("signal_registry", {
|
|
3893
|
+
onConflict: {
|
|
3894
|
+
target: ["name"],
|
|
3895
|
+
action: {
|
|
3896
|
+
do: "nothing"
|
|
3858
3897
|
}
|
|
3859
|
-
}
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3898
|
+
}
|
|
3899
|
+
}).then(
|
|
3900
|
+
CadenzaService.createMetaTask("Process signal registration", (ctx) => {
|
|
3901
|
+
return { __signalName: ctx.signalRegistry?.name };
|
|
3902
|
+
}).then(CadenzaService.broker.registerSignalTask)
|
|
3903
|
+
)
|
|
3904
|
+
);
|
|
3905
|
+
this.splitTasksForRegistration = CadenzaService.createMetaTask(
|
|
3906
|
+
"Split tasks for registration",
|
|
3907
|
+
function* (ctx) {
|
|
3908
|
+
const tasks = ctx.__tasks;
|
|
3909
|
+
for (const task of tasks) {
|
|
3910
|
+
if (task.registered) continue;
|
|
3911
|
+
const { __functionString, __getTagCallback } = task.export();
|
|
3912
|
+
yield {
|
|
3913
|
+
data: {
|
|
3914
|
+
name: task.name,
|
|
3915
|
+
version: task.version,
|
|
3916
|
+
description: task.description,
|
|
3917
|
+
functionString: __functionString,
|
|
3918
|
+
tagIdGetter: __getTagCallback,
|
|
3919
|
+
layerIndex: task.layerIndex,
|
|
3920
|
+
concurrency: task.concurrency,
|
|
3921
|
+
timeout: task.timeout,
|
|
3922
|
+
isUnique: task.isUnique,
|
|
3923
|
+
isSignal: task.isSignal,
|
|
3924
|
+
isThrottled: task.isThrottled,
|
|
3925
|
+
isDebounce: task.isDebounce,
|
|
3926
|
+
isEphemeral: task.isEphemeral,
|
|
3927
|
+
isMeta: task.isMeta,
|
|
3928
|
+
isSubMeta: task.isSubMeta,
|
|
3929
|
+
isHidden: task.isHidden,
|
|
3930
|
+
// inputSchema: task.inputSchema,
|
|
3931
|
+
validateInputContext: task.validateInputContext,
|
|
3932
|
+
// outputSchema: task.outputSchema,
|
|
3933
|
+
validateOutputContext: task.validateOutputContext,
|
|
3934
|
+
retryCount: task.retryCount,
|
|
3935
|
+
retryDelay: task.retryDelay,
|
|
3936
|
+
retryDelayMax: task.retryDelayMax,
|
|
3937
|
+
retryDelayFactor: task.retryDelayFactor,
|
|
3938
|
+
service_name: CadenzaService.serviceRegistry.serviceName
|
|
3939
|
+
},
|
|
3940
|
+
__name: task.name
|
|
3941
|
+
};
|
|
3942
|
+
}
|
|
3863
3943
|
}
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
task.registered = true;
|
|
3871
|
-
const { __functionString, __getTagCallback } = task.export();
|
|
3872
|
-
emit("meta.sync_controller.task_added", {
|
|
3873
|
-
data: {
|
|
3874
|
-
name: task.name,
|
|
3875
|
-
version: task.version,
|
|
3876
|
-
description: task.description,
|
|
3877
|
-
functionString: __functionString,
|
|
3878
|
-
tagIdGetter: __getTagCallback,
|
|
3879
|
-
layerIndex: task.layerIndex,
|
|
3880
|
-
concurrency: task.concurrency,
|
|
3881
|
-
timeout: task.timeout,
|
|
3882
|
-
isUnique: task.isUnique,
|
|
3883
|
-
isSignal: task.isSignal,
|
|
3884
|
-
isThrottled: task.isThrottled,
|
|
3885
|
-
isDebounce: task.isDebounce,
|
|
3886
|
-
isEphemeral: task.isEphemeral,
|
|
3887
|
-
isMeta: task.isMeta,
|
|
3888
|
-
isSubMeta: task.isSubMeta,
|
|
3889
|
-
isHidden: task.isHidden,
|
|
3890
|
-
// inputSchema: task.inputSchema,
|
|
3891
|
-
validateInputContext: task.validateInputContext,
|
|
3892
|
-
// outputSchema: task.outputSchema,
|
|
3893
|
-
validateOutputContext: task.validateOutputContext,
|
|
3894
|
-
retryCount: task.retryCount,
|
|
3895
|
-
retryDelay: task.retryDelay,
|
|
3896
|
-
retryDelayMax: task.retryDelayMax,
|
|
3897
|
-
retryDelayFactor: task.retryDelayFactor,
|
|
3898
|
-
service_name: CadenzaService.serviceRegistry.serviceName
|
|
3944
|
+
).then(
|
|
3945
|
+
CadenzaService.createCadenzaDBInsertTask("task", {
|
|
3946
|
+
onConflict: {
|
|
3947
|
+
target: ["name", "service_name", "version"],
|
|
3948
|
+
action: {
|
|
3949
|
+
do: "nothing"
|
|
3899
3950
|
}
|
|
3900
|
-
}
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3951
|
+
}
|
|
3952
|
+
}).then(
|
|
3953
|
+
CadenzaService.createMetaTask("Record registration", (ctx) => {
|
|
3954
|
+
CadenzaService.get(ctx.__name).registered = true;
|
|
3955
|
+
})
|
|
3956
|
+
)
|
|
3957
|
+
);
|
|
3958
|
+
const registerSignalTask = CadenzaService.createMetaTask(
|
|
3959
|
+
"Record signal registration",
|
|
3960
|
+
(ctx) => {
|
|
3961
|
+
CadenzaService.get(ctx.__name)?.registeredSignals.add(ctx.__signalName);
|
|
3962
|
+
}
|
|
3963
|
+
);
|
|
3964
|
+
this.registerSignalToTaskMapTask = CadenzaService.createMetaTask(
|
|
3965
|
+
"Split observed signals of task",
|
|
3966
|
+
function* (ctx) {
|
|
3967
|
+
const task = ctx.__task;
|
|
3968
|
+
if (task.hidden || !task.register) return;
|
|
3969
|
+
for (const signal of task.observedSignals) {
|
|
3970
|
+
let firstChar = signal.charAt(0);
|
|
3904
3971
|
let signalServiceName;
|
|
3972
|
+
let _signal = signal;
|
|
3905
3973
|
if (firstChar === firstChar.toUpperCase() && firstChar !== firstChar.toLowerCase()) {
|
|
3906
3974
|
signalServiceName = signal.split(".")[0];
|
|
3907
3975
|
_signal = signal.split(".").slice(1).join(".");
|
|
3908
3976
|
}
|
|
3909
|
-
|
|
3977
|
+
if (task.registeredSignals.has(_signal)) continue;
|
|
3978
|
+
yield {
|
|
3910
3979
|
data: {
|
|
3911
3980
|
signalName: _signal,
|
|
3912
3981
|
taskName: task.name,
|
|
3913
3982
|
taskVersion: task.version,
|
|
3914
3983
|
taskServiceName: CadenzaService.serviceRegistry.serviceName,
|
|
3915
3984
|
signalServiceName: signalServiceName ?? CadenzaService.serviceRegistry.serviceName
|
|
3916
|
-
}
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3985
|
+
},
|
|
3986
|
+
__name: task.name,
|
|
3987
|
+
__signalName: _signal
|
|
3988
|
+
};
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
).then(
|
|
3992
|
+
CadenzaService.createCadenzaDBInsertTask("signal_to_task_map", {
|
|
3993
|
+
onConflict: {
|
|
3994
|
+
target: [
|
|
3995
|
+
"task_name",
|
|
3996
|
+
"task_version",
|
|
3997
|
+
"task_service_name",
|
|
3998
|
+
"signal_name",
|
|
3999
|
+
"signal_service_name"
|
|
4000
|
+
],
|
|
4001
|
+
action: {
|
|
4002
|
+
do: "nothing"
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
}).then(registerSignalTask)
|
|
4006
|
+
);
|
|
4007
|
+
this.registerTaskToSignalMapTask = CadenzaService.createMetaTask(
|
|
4008
|
+
"Split emitted signals of task",
|
|
4009
|
+
function* (ctx) {
|
|
4010
|
+
const task = ctx.__task;
|
|
4011
|
+
if (task.hidden || !task.register) return;
|
|
4012
|
+
for (const signal of task.signalsToEmitAfter) {
|
|
4013
|
+
if (task.registeredSignals.has(signal)) continue;
|
|
4014
|
+
yield {
|
|
3921
4015
|
data: {
|
|
3922
4016
|
signalName: signal,
|
|
3923
4017
|
taskName: task.name,
|
|
3924
4018
|
taskVersion: task.version,
|
|
3925
4019
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3926
|
-
}
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
4020
|
+
},
|
|
4021
|
+
__signalName: signal,
|
|
4022
|
+
__name: task.name
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
for (const signal of task.signalsToEmitOnFail) {
|
|
4026
|
+
if (task.registeredSignals.has(signal)) continue;
|
|
4027
|
+
yield {
|
|
3932
4028
|
data: {
|
|
3933
4029
|
signalName: signal,
|
|
3934
4030
|
taskName: task.name,
|
|
3935
4031
|
taskVersion: task.version,
|
|
3936
4032
|
serviceName: CadenzaService.serviceRegistry.serviceName,
|
|
3937
4033
|
isOnFail: true
|
|
3938
|
-
}
|
|
3939
|
-
|
|
3940
|
-
|
|
4034
|
+
},
|
|
4035
|
+
__signalName: signal,
|
|
4036
|
+
__name: task.name
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
3941
4039
|
}
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
4040
|
+
).then(
|
|
4041
|
+
CadenzaService.createCadenzaDBInsertTask("task_to_signal_map", {
|
|
4042
|
+
onConflict: {
|
|
4043
|
+
target: ["task_name", "task_version", "service_name", "signal_name"],
|
|
4044
|
+
action: {
|
|
4045
|
+
do: "nothing"
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4048
|
+
}).then(registerSignalTask)
|
|
4049
|
+
);
|
|
4050
|
+
this.registerTaskMapTask = CadenzaService.createMetaTask(
|
|
4051
|
+
"Register task map to DB",
|
|
4052
|
+
function* (ctx) {
|
|
4053
|
+
const task = ctx.__task;
|
|
4054
|
+
if (task.hidden || !task.register) return;
|
|
4055
|
+
for (const t of task.nextTasks) {
|
|
4056
|
+
if (task.taskMapRegistration.has(t.name)) {
|
|
4057
|
+
continue;
|
|
4058
|
+
}
|
|
4059
|
+
yield {
|
|
3946
4060
|
data: {
|
|
3947
4061
|
taskName: t.name,
|
|
3948
4062
|
taskVersion: t.version,
|
|
3949
4063
|
predecessorTaskName: task.name,
|
|
3950
4064
|
predecessorTaskVersion: task.version,
|
|
3951
4065
|
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
|
|
4066
|
+
},
|
|
4067
|
+
__name: task.name,
|
|
4068
|
+
__nextTaskName: t.name
|
|
4069
|
+
};
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
).then(
|
|
4073
|
+
CadenzaService.createCadenzaDBInsertTask("directional_task_graph_map", {
|
|
4074
|
+
onConflict: {
|
|
4075
|
+
target: [
|
|
4076
|
+
"task_name",
|
|
4077
|
+
"predecessor_task_name",
|
|
4078
|
+
"task_version",
|
|
4079
|
+
"predecessor_task_version",
|
|
4080
|
+
"service_name"
|
|
4081
|
+
],
|
|
4082
|
+
action: {
|
|
4083
|
+
do: "nothing"
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
}).then(
|
|
4087
|
+
CadenzaService.createMetaTask("Record task map registration", (ctx) => {
|
|
4088
|
+
CadenzaService.get(ctx.__name)?.taskMapRegistration.add(ctx.__nextTaskName);
|
|
4089
|
+
})
|
|
4090
|
+
)
|
|
4091
|
+
);
|
|
4092
|
+
this.registerDeputyRelationshipTask = CadenzaService.createMetaTask(
|
|
4093
|
+
"Register deputy relationship",
|
|
4094
|
+
(ctx) => {
|
|
4095
|
+
const task = ctx.__task;
|
|
4096
|
+
if (task.hidden || !task.register) return;
|
|
3955
4097
|
if (task.isDeputy && !task.signalName) {
|
|
3956
|
-
|
|
4098
|
+
if (task.registeredDeputyMap) return;
|
|
4099
|
+
return {
|
|
3957
4100
|
data: {
|
|
3958
4101
|
triggered_task_name: task.remoteRoutineName,
|
|
3959
4102
|
triggered_task_version: 1,
|
|
@@ -3961,12 +4104,56 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
3961
4104
|
deputy_task_name: task.name,
|
|
3962
4105
|
deputy_task_version: task.version,
|
|
3963
4106
|
deputy_service_name: CadenzaService.serviceRegistry.serviceName
|
|
3964
|
-
}
|
|
3965
|
-
|
|
4107
|
+
},
|
|
4108
|
+
__name: task.name
|
|
4109
|
+
};
|
|
3966
4110
|
}
|
|
3967
4111
|
}
|
|
3968
|
-
|
|
3969
|
-
|
|
4112
|
+
).then(
|
|
4113
|
+
CadenzaService.createCadenzaDBInsertTask("directional_task_graph_map", {
|
|
4114
|
+
onConflict: {
|
|
4115
|
+
target: [
|
|
4116
|
+
"task_name",
|
|
4117
|
+
"predecessor_task_name",
|
|
4118
|
+
"task_version",
|
|
4119
|
+
"predecessor_task_version",
|
|
4120
|
+
"service_name"
|
|
4121
|
+
],
|
|
4122
|
+
action: {
|
|
4123
|
+
do: "nothing"
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
}).then(
|
|
4127
|
+
CadenzaService.createMetaTask(
|
|
4128
|
+
"Record deputy relationship registration",
|
|
4129
|
+
(ctx) => {
|
|
4130
|
+
CadenzaService.get(ctx.__name).registeredDeputyMap = true;
|
|
4131
|
+
}
|
|
4132
|
+
)
|
|
4133
|
+
)
|
|
4134
|
+
);
|
|
4135
|
+
CadenzaService.createDebounceMetaTask(
|
|
4136
|
+
"Debounce syncing of resources",
|
|
4137
|
+
() => true,
|
|
4138
|
+
"",
|
|
4139
|
+
500
|
|
4140
|
+
).doAfter(CadenzaService.serviceRegistry.handleInstanceUpdateTask).then(
|
|
4141
|
+
CadenzaService.broker.getSignalsTask.clone().then(
|
|
4142
|
+
this.splitSignalsTask,
|
|
4143
|
+
CadenzaService.registry.getAllTasks.clone().then(
|
|
4144
|
+
this.splitTasksForRegistration,
|
|
4145
|
+
CadenzaService.registry.getAllRoutines.clone().then(
|
|
4146
|
+
this.splitRoutinesTask,
|
|
4147
|
+
CadenzaService.registry.doForEachTask.clone().then(
|
|
4148
|
+
this.registerTaskMapTask,
|
|
4149
|
+
this.registerSignalToTaskMapTask,
|
|
4150
|
+
this.registerTaskToSignalMapTask,
|
|
4151
|
+
this.registerDeputyRelationshipTask
|
|
4152
|
+
)
|
|
4153
|
+
)
|
|
4154
|
+
)
|
|
4155
|
+
)
|
|
4156
|
+
);
|
|
3970
4157
|
}
|
|
3971
4158
|
};
|
|
3972
4159
|
|
|
@@ -4087,6 +4274,18 @@ var CadenzaService = class {
|
|
|
4087
4274
|
static run(task, context) {
|
|
4088
4275
|
this.runner?.run(task, context);
|
|
4089
4276
|
}
|
|
4277
|
+
static schedule(taskName, context, timeoutMs, exactDateTime) {
|
|
4278
|
+
this.broker?.schedule(taskName, context, timeoutMs, exactDateTime);
|
|
4279
|
+
}
|
|
4280
|
+
static throttle(taskName, context, intervalMs, leading = false, startDateTime) {
|
|
4281
|
+
this.broker?.throttle(
|
|
4282
|
+
taskName,
|
|
4283
|
+
context,
|
|
4284
|
+
intervalMs,
|
|
4285
|
+
leading,
|
|
4286
|
+
startDateTime
|
|
4287
|
+
);
|
|
4288
|
+
}
|
|
4090
4289
|
/**
|
|
4091
4290
|
* Logs a message with a specified log level and additional contextual data.
|
|
4092
4291
|
* Records in the CadenzaDB when available.
|
|
@@ -4121,6 +4320,9 @@ var CadenzaService = class {
|
|
|
4121
4320
|
}
|
|
4122
4321
|
});
|
|
4123
4322
|
}
|
|
4323
|
+
static get(taskName) {
|
|
4324
|
+
return import_core3.default.get(taskName);
|
|
4325
|
+
}
|
|
4124
4326
|
/**
|
|
4125
4327
|
* Creates a new DeputyTask instance based on the provided routine name, service name, and options.
|
|
4126
4328
|
* This method ensures proper task initialization, including setting a unique name,
|
|
@@ -4579,9 +4781,6 @@ var CadenzaService = class {
|
|
|
4579
4781
|
GraphMetadataController.instance;
|
|
4580
4782
|
GraphSyncController.instance;
|
|
4581
4783
|
this.broker.schedule("meta.sync_requested", {}, 2e3);
|
|
4582
|
-
if (options.cadenzaDB?.connect) {
|
|
4583
|
-
this.broker.throttle("meta.sync_requested", {}, 3e5);
|
|
4584
|
-
}
|
|
4585
4784
|
this.log("Service created.");
|
|
4586
4785
|
return true;
|
|
4587
4786
|
}).doOn("meta.service_registry.instance_inserted");
|