@cadenza.io/service 2.3.13 → 2.3.15

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.js CHANGED
@@ -178,6 +178,7 @@ var DeputyTask = class extends import_core.Task {
178
178
  const ctx = context.getContext();
179
179
  const metadata = context.getMetadata();
180
180
  const deputyContext = {
181
+ __timeout: this.timeout,
181
182
  __localTaskName: this.name,
182
183
  __localTaskVersion: this.version,
183
184
  __localServiceName: CadenzaService.serviceRegistry.serviceName,
@@ -550,17 +551,22 @@ var ServiceRegistry = class _ServiceRegistry {
550
551
  const mergeSyncDataTask = CadenzaService.createUniqueMetaTask(
551
552
  "Merge sync data",
552
553
  (ctx) => {
553
- let joinedContext = {};
554
- ctx.joinedContexts.forEach((ctx2) => {
555
- joinedContext = { ...joinedContext, ...ctx2 };
556
- });
557
- console.log(
558
- "merging contexts of full sync...",
559
- joinedContext.keys().join(", ")
560
- );
561
- return joinedContext;
554
+ try {
555
+ let joinedContext = {};
556
+ ctx.joinedContexts.forEach((ctx2) => {
557
+ joinedContext = { ...joinedContext, ...ctx2 };
558
+ });
559
+ console.log(
560
+ "merging contexts of full sync...",
561
+ joinedContext.keys().join(", ")
562
+ );
563
+ return joinedContext;
564
+ } catch (e) {
565
+ console.log("Error", e.message, ctx);
566
+ return false;
567
+ }
562
568
  }
563
- ).then(this.handleGlobalSignalRegistrationTask);
569
+ ).emits("meta.service_registry.initial_sync_complete").then(this.handleGlobalSignalRegistrationTask);
564
570
  this.fullSyncTask = CadenzaService.createMetaRoutine("Full sync", [
565
571
  CadenzaService.createTask("Confirm full sync", () => {
566
572
  console.log("Confirming full sync...");
@@ -1950,7 +1956,7 @@ var SocketController = class _SocketController {
1950
1956
  transports: ["websocket"],
1951
1957
  autoConnect: false
1952
1958
  });
1953
- emitWhenReady = (event, data, timeoutMs = 2e4, ack) => {
1959
+ emitWhenReady = (event, data, timeoutMs = 6e4, ack) => {
1954
1960
  return new Promise((resolve) => {
1955
1961
  const tryEmit = () => {
1956
1962
  if (!socket?.connected) {
@@ -1984,7 +1990,12 @@ var SocketController = class _SocketController {
1984
1990
  if (err) {
1985
1991
  CadenzaService.log(
1986
1992
  "Socket timeout.",
1987
- { error: err.message, socketId: socket?.id, serviceName },
1993
+ {
1994
+ event,
1995
+ error: err.message,
1996
+ socketId: socket?.id,
1997
+ serviceName
1998
+ },
1988
1999
  "warning"
1989
2000
  );
1990
2001
  response = {
@@ -2102,13 +2113,6 @@ var SocketController = class _SocketController {
2102
2113
  "warning"
2103
2114
  );
2104
2115
  }
2105
- if (result.errored) {
2106
- errorCount++;
2107
- if (errorCount > ERROR_LIMIT) {
2108
- console.error("Too many errors, closing socket", URL);
2109
- emit(`meta.socket_shutdown_requested:${fetchId}`, {});
2110
- }
2111
- }
2112
2116
  }
2113
2117
  );
2114
2118
  },
@@ -2129,7 +2133,7 @@ var SocketController = class _SocketController {
2129
2133
  emitWhenReady?.(
2130
2134
  "delegation",
2131
2135
  ctx2,
2132
- 2e4,
2136
+ ctx2.__timeout ?? 6e4,
2133
2137
  (resultContext) => {
2134
2138
  const requestDuration = Date.now() - requestSentAt;
2135
2139
  const metadata = resultContext.__metadata;
@@ -2149,13 +2153,6 @@ var SocketController = class _SocketController {
2149
2153
  }
2150
2154
  );
2151
2155
  pendingDelegationIds.delete(ctx2.__metadata.__deputyExecId);
2152
- if (resultContext.errored) {
2153
- errorCount++;
2154
- if (errorCount > ERROR_LIMIT) {
2155
- console.error("Too many errors, closing socket", URL);
2156
- emit(`meta.socket_shutdown_requested:${fetchId}`, {});
2157
- }
2158
- }
2159
2156
  resolve(resultContext);
2160
2157
  }
2161
2158
  );
@@ -2182,13 +2179,6 @@ var SocketController = class _SocketController {
2182
2179
  response
2183
2180
  );
2184
2181
  }
2185
- if (response.errored) {
2186
- errorCount++;
2187
- if (errorCount > ERROR_LIMIT) {
2188
- console.error("Too many errors, closing socket", URL);
2189
- emit(`meta.socket_shutdown_requested:${fetchId}`, {});
2190
- }
2191
- }
2192
2182
  resolve(response);
2193
2183
  });
2194
2184
  });
@@ -3831,14 +3821,14 @@ var GraphSyncController = class _GraphSyncController {
3831
3821
  }
3832
3822
  }
3833
3823
  },
3834
- { concurrency: 50 }
3824
+ { concurrency: 30 }
3835
3825
  ) : CadenzaService.get("dbInsertRoutine"))?.then(
3836
3826
  CadenzaService.createMetaTask("Register routine", (ctx) => {
3837
3827
  if (!ctx.__syncing) {
3838
3828
  return;
3839
3829
  }
3840
3830
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
3841
- delayMs: 2e3
3831
+ delayMs: 3e3
3842
3832
  });
3843
3833
  CadenzaService.getRoutine(ctx.__routineName).registered = true;
3844
3834
  return true;
@@ -3856,7 +3846,7 @@ var GraphSyncController = class _GraphSyncController {
3856
3846
  const { routines } = ctx;
3857
3847
  if (!routines) return;
3858
3848
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
3859
- delayMs: 2e3
3849
+ delayMs: 3e3
3860
3850
  });
3861
3851
  for (const routine of routines) {
3862
3852
  for (const task of routine.tasks) {
@@ -3900,7 +3890,7 @@ var GraphSyncController = class _GraphSyncController {
3900
3890
  }
3901
3891
  }
3902
3892
  },
3903
- { concurrency: 50 }
3893
+ { concurrency: 30 }
3904
3894
  ) : CadenzaService.get("dbInsertTaskToRoutineMap"))?.then(
3905
3895
  CadenzaService.createMetaTask("Register routine task", (ctx) => {
3906
3896
  if (!ctx.__syncing) {
@@ -3919,7 +3909,7 @@ var GraphSyncController = class _GraphSyncController {
3919
3909
  "Split signals for registration",
3920
3910
  function* (ctx) {
3921
3911
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
3922
- delayMs: 2e3
3912
+ delayMs: 3e3
3923
3913
  });
3924
3914
  const { signals } = ctx;
3925
3915
  if (!signals) return;
@@ -3951,14 +3941,14 @@ var GraphSyncController = class _GraphSyncController {
3951
3941
  }
3952
3942
  }
3953
3943
  },
3954
- { concurrency: 50 }
3944
+ { concurrency: 30 }
3955
3945
  ) : CadenzaService.get("dbInsertSignalRegistry"))?.then(
3956
3946
  CadenzaService.createMetaTask("Process signal registration", (ctx) => {
3957
3947
  if (!ctx.__syncing) {
3958
3948
  return;
3959
3949
  }
3960
3950
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
3961
- delayMs: 2e3
3951
+ delayMs: 3e3
3962
3952
  });
3963
3953
  return { signalName: ctx.__signal };
3964
3954
  }).then(
@@ -3974,7 +3964,7 @@ var GraphSyncController = class _GraphSyncController {
3974
3964
  "Split tasks for registration",
3975
3965
  function* (ctx) {
3976
3966
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
3977
- delayMs: 2e3
3967
+ delayMs: 3e3
3978
3968
  });
3979
3969
  const tasks = ctx.tasks;
3980
3970
  for (const task of tasks) {
@@ -4029,14 +4019,14 @@ var GraphSyncController = class _GraphSyncController {
4029
4019
  }
4030
4020
  }
4031
4021
  },
4032
- { concurrency: 50 }
4022
+ { concurrency: 30 }
4033
4023
  ) : CadenzaService.get("dbInsertTask"))?.then(
4034
4024
  CadenzaService.createMetaTask("Record registration", (ctx) => {
4035
4025
  if (!ctx.__syncing) {
4036
4026
  return;
4037
4027
  }
4038
4028
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
4039
- delayMs: 2e3
4029
+ delayMs: 3e3
4040
4030
  });
4041
4031
  CadenzaService.get(ctx.__taskName).registered = true;
4042
4032
  return true;
@@ -4055,7 +4045,7 @@ var GraphSyncController = class _GraphSyncController {
4055
4045
  return;
4056
4046
  }
4057
4047
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
4058
- delayMs: 2e3
4048
+ delayMs: 3e3
4059
4049
  });
4060
4050
  CadenzaService.get(ctx.__taskName)?.registeredSignals.add(ctx.__signal);
4061
4051
  }
@@ -4098,7 +4088,7 @@ var GraphSyncController = class _GraphSyncController {
4098
4088
  }
4099
4089
  }
4100
4090
  },
4101
- { concurrency: 50 }
4091
+ { concurrency: 30 }
4102
4092
  ) : CadenzaService.get("dbInsertSignalToTaskMap"))?.then(registerSignalTask)
4103
4093
  );
4104
4094
  this.registerTaskMapTask = CadenzaService.createMetaTask(
@@ -4106,7 +4096,7 @@ var GraphSyncController = class _GraphSyncController {
4106
4096
  function* (ctx) {
4107
4097
  const task = ctx.task;
4108
4098
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
4109
- delayMs: 2e3
4099
+ delayMs: 3e3
4110
4100
  });
4111
4101
  if (task.hidden || !task.register) return;
4112
4102
  for (const t of task.nextTasks) {
@@ -4145,14 +4135,14 @@ var GraphSyncController = class _GraphSyncController {
4145
4135
  }
4146
4136
  }
4147
4137
  },
4148
- { concurrency: 50 }
4138
+ { concurrency: 30 }
4149
4139
  ) : CadenzaService.get("dbInsertDirectionalTaskGraphMap"))?.then(
4150
4140
  CadenzaService.createMetaTask("Record task map registration", (ctx) => {
4151
4141
  if (!ctx.__syncing) {
4152
4142
  return;
4153
4143
  }
4154
4144
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
4155
- delayMs: 2e3
4145
+ delayMs: 3e3
4156
4146
  });
4157
4147
  CadenzaService.get(ctx.__taskName)?.taskMapRegistration.add(
4158
4148
  ctx.__nextTaskName
@@ -4198,7 +4188,7 @@ var GraphSyncController = class _GraphSyncController {
4198
4188
  }
4199
4189
  }
4200
4190
  },
4201
- { concurrency: 50 }
4191
+ { concurrency: 30 }
4202
4192
  ) : CadenzaService.get("dbInsertDirectionalTaskGraphMap"))?.then(
4203
4193
  CadenzaService.createMetaTask(
4204
4194
  "Record deputy relationship registration",
@@ -4207,14 +4197,17 @@ var GraphSyncController = class _GraphSyncController {
4207
4197
  return;
4208
4198
  }
4209
4199
  CadenzaService.debounce("meta.sync_controller.synced_resource", {
4210
- delayMs: 2e3
4200
+ delayMs: 3e3
4211
4201
  });
4212
4202
  CadenzaService.get(ctx.__taskName).registeredDeputyMap = true;
4213
4203
  }
4214
4204
  )
4215
4205
  )
4216
4206
  );
4217
- CadenzaService.signalBroker.getSignalsTask.clone().doOn("meta.sync_controller.sync_tick", "meta.sync_requested").then(this.splitSignalsTask);
4207
+ CadenzaService.signalBroker.getSignalsTask.clone().doOn(
4208
+ "meta.sync_controller.sync_tick",
4209
+ "meta.service_registry.initial_sync_complete"
4210
+ ).then(this.splitSignalsTask);
4218
4211
  CadenzaService.registry.getAllTasks.clone().doOn("meta.sync_controller.synced_signals").then(this.splitTasksForRegistration);
4219
4212
  CadenzaService.registry.getAllRoutines.clone().doOn("meta.sync_controller.synced_tasks").then(this.splitRoutinesTask);
4220
4213
  CadenzaService.registry.doForEachTask.clone().doOn("meta.sync_controller.synced_tasks").then(
@@ -4250,7 +4243,7 @@ var GraphSyncController = class _GraphSyncController {
4250
4243
  { __syncing: true },
4251
4244
  18e4
4252
4245
  );
4253
- CadenzaService.schedule("meta.sync_requested", { __syncing: true }, 5e3);
4246
+ CadenzaService.schedule("meta.sync_requested", { __syncing: true }, 2e3);
4254
4247
  }
4255
4248
  console.log("Syncing initiated", this.isCadenzaDBReady);
4256
4249
  }