atomic-queues 1.6.2 → 2.0.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.
Files changed (337) hide show
  1. package/README.md +182 -411
  2. package/dist/cli/generators/json-schema.d.ts +3 -0
  3. package/dist/cli/generators/json-schema.d.ts.map +1 -0
  4. package/dist/cli/generators/json-schema.js +31 -0
  5. package/dist/cli/generators/json-schema.js.map +1 -0
  6. package/dist/cli/generators/typescript.d.ts +3 -0
  7. package/dist/cli/generators/typescript.d.ts.map +1 -0
  8. package/dist/cli/generators/typescript.js +62 -0
  9. package/dist/cli/generators/typescript.js.map +1 -0
  10. package/dist/cli/index.d.ts +3 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +156 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/decorators/actor.decorators.d.ts +4 -0
  15. package/dist/decorators/actor.decorators.d.ts.map +1 -0
  16. package/dist/decorators/actor.decorators.js +32 -0
  17. package/dist/decorators/actor.decorators.js.map +1 -0
  18. package/dist/decorators/constants.d.ts +5 -12
  19. package/dist/decorators/constants.d.ts.map +1 -1
  20. package/dist/decorators/constants.js +10 -16
  21. package/dist/decorators/constants.js.map +1 -1
  22. package/dist/decorators/index.d.ts +4 -4
  23. package/dist/decorators/index.d.ts.map +1 -1
  24. package/dist/decorators/index.js +4 -4
  25. package/dist/decorators/index.js.map +1 -1
  26. package/dist/decorators/interfaces.d.ts +18 -78
  27. package/dist/decorators/interfaces.d.ts.map +1 -1
  28. package/dist/decorators/metadata-readers.d.ts +5 -26
  29. package/dist/decorators/metadata-readers.d.ts.map +1 -1
  30. package/dist/decorators/metadata-readers.js +16 -33
  31. package/dist/decorators/metadata-readers.js.map +1 -1
  32. package/dist/decorators/schema.decorators.d.ts +2 -0
  33. package/dist/decorators/schema.decorators.d.ts.map +1 -0
  34. package/dist/decorators/schema.decorators.js +13 -0
  35. package/dist/decorators/schema.decorators.js.map +1 -0
  36. package/dist/domain/interfaces/config.interfaces.d.ts +52 -153
  37. package/dist/domain/interfaces/config.interfaces.d.ts.map +1 -1
  38. package/dist/domain/interfaces/index.d.ts +0 -7
  39. package/dist/domain/interfaces/index.d.ts.map +1 -1
  40. package/dist/domain/interfaces/index.js +0 -7
  41. package/dist/domain/interfaces/index.js.map +1 -1
  42. package/dist/domain/interfaces/job.interfaces.d.ts +32 -65
  43. package/dist/domain/interfaces/job.interfaces.d.ts.map +1 -1
  44. package/dist/index.d.ts +0 -34
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +0 -39
  47. package/dist/index.js.map +1 -1
  48. package/dist/module/atomic-queues.module.d.ts +0 -83
  49. package/dist/module/atomic-queues.module.d.ts.map +1 -1
  50. package/dist/module/atomic-queues.module.js +35 -134
  51. package/dist/module/atomic-queues.module.js.map +1 -1
  52. package/dist/services/actor-registry/actor-registry.service.d.ts +30 -0
  53. package/dist/services/actor-registry/actor-registry.service.d.ts.map +1 -0
  54. package/dist/services/actor-registry/actor-registry.service.js +186 -0
  55. package/dist/services/actor-registry/actor-registry.service.js.map +1 -0
  56. package/dist/services/actor-registry/index.d.ts +2 -0
  57. package/dist/services/actor-registry/index.d.ts.map +1 -0
  58. package/dist/services/actor-registry/index.js +18 -0
  59. package/dist/services/actor-registry/index.js.map +1 -0
  60. package/dist/services/actor-system/actor-system.service.d.ts +19 -0
  61. package/dist/services/actor-system/actor-system.service.d.ts.map +1 -0
  62. package/dist/services/actor-system/actor-system.service.js +86 -0
  63. package/dist/services/actor-system/actor-system.service.js.map +1 -0
  64. package/dist/services/actor-system/index.d.ts +2 -0
  65. package/dist/services/actor-system/index.d.ts.map +1 -0
  66. package/dist/services/{cron-manager → actor-system}/index.js +1 -1
  67. package/dist/services/actor-system/index.js.map +1 -0
  68. package/dist/services/command-discovery/command-discovery.service.d.ts +6 -53
  69. package/dist/services/command-discovery/command-discovery.service.d.ts.map +1 -1
  70. package/dist/services/command-discovery/command-discovery.service.js +0 -59
  71. package/dist/services/command-discovery/command-discovery.service.js.map +1 -1
  72. package/dist/services/constants.d.ts +2 -9
  73. package/dist/services/constants.d.ts.map +1 -1
  74. package/dist/services/constants.js +3 -10
  75. package/dist/services/constants.js.map +1 -1
  76. package/dist/services/executor-pool/executor-pool.service.d.ts +31 -0
  77. package/dist/services/executor-pool/executor-pool.service.d.ts.map +1 -0
  78. package/dist/services/executor-pool/executor-pool.service.js +147 -0
  79. package/dist/services/executor-pool/executor-pool.service.js.map +1 -0
  80. package/dist/services/executor-pool/index.d.ts +2 -0
  81. package/dist/services/executor-pool/index.d.ts.map +1 -0
  82. package/dist/services/{queue-manager → executor-pool}/index.js +1 -1
  83. package/dist/services/executor-pool/index.js.map +1 -0
  84. package/dist/services/gate/gate.service.d.ts +17 -0
  85. package/dist/services/gate/gate.service.d.ts.map +1 -0
  86. package/dist/services/gate/gate.service.js +66 -0
  87. package/dist/services/gate/gate.service.js.map +1 -0
  88. package/dist/services/gate/index.d.ts +2 -0
  89. package/dist/services/gate/index.d.ts.map +1 -0
  90. package/dist/services/{spawn-queue → gate}/index.js +1 -1
  91. package/dist/services/gate/index.js.map +1 -0
  92. package/dist/services/handler-executor/handler-executor.service.d.ts +32 -0
  93. package/dist/services/handler-executor/handler-executor.service.d.ts.map +1 -0
  94. package/dist/services/handler-executor/handler-executor.service.js +186 -0
  95. package/dist/services/handler-executor/handler-executor.service.js.map +1 -0
  96. package/dist/services/handler-executor/index.d.ts +2 -0
  97. package/dist/services/handler-executor/index.d.ts.map +1 -0
  98. package/dist/services/handler-executor/index.js +18 -0
  99. package/dist/services/handler-executor/index.js.map +1 -0
  100. package/dist/services/index.d.ts +11 -12
  101. package/dist/services/index.d.ts.map +1 -1
  102. package/dist/services/index.js +11 -12
  103. package/dist/services/index.js.map +1 -1
  104. package/dist/services/log/index.d.ts +2 -0
  105. package/dist/services/log/index.d.ts.map +1 -0
  106. package/dist/services/{index-manager → log}/index.js +1 -1
  107. package/dist/services/log/index.js.map +1 -0
  108. package/dist/services/log/log.service.d.ts +21 -0
  109. package/dist/services/log/log.service.d.ts.map +1 -0
  110. package/dist/services/log/log.service.js +92 -0
  111. package/dist/services/log/log.service.js.map +1 -0
  112. package/dist/services/queue-bus/index.d.ts +0 -4
  113. package/dist/services/queue-bus/index.d.ts.map +1 -1
  114. package/dist/services/queue-bus/index.js +0 -4
  115. package/dist/services/queue-bus/index.js.map +1 -1
  116. package/dist/services/queue-bus/queue-bus.service.d.ts +44 -198
  117. package/dist/services/queue-bus/queue-bus.service.d.ts.map +1 -1
  118. package/dist/services/queue-bus/queue-bus.service.js +103 -259
  119. package/dist/services/queue-bus/queue-bus.service.js.map +1 -1
  120. package/dist/services/queue-bus/queue-bus.utils.d.ts +0 -28
  121. package/dist/services/queue-bus/queue-bus.utils.d.ts.map +1 -1
  122. package/dist/services/queue-bus/queue-bus.utils.js +1 -41
  123. package/dist/services/queue-bus/queue-bus.utils.js.map +1 -1
  124. package/dist/services/registry/index.d.ts +4 -0
  125. package/dist/services/registry/index.d.ts.map +1 -0
  126. package/dist/services/{queue-events-manager → registry}/index.js +3 -1
  127. package/dist/services/registry/index.js.map +1 -0
  128. package/dist/services/registry/registry.service.d.ts +43 -0
  129. package/dist/services/registry/registry.service.d.ts.map +1 -0
  130. package/dist/services/registry/registry.service.js +379 -0
  131. package/dist/services/registry/registry.service.js.map +1 -0
  132. package/dist/services/registry/registry.types.d.ts +24 -0
  133. package/dist/services/registry/registry.types.d.ts.map +1 -0
  134. package/dist/{domain/interfaces/lock.interfaces.js → services/registry/registry.types.js} +1 -1
  135. package/dist/services/registry/registry.types.js.map +1 -0
  136. package/dist/services/registry/schema-converter.d.ts +2 -0
  137. package/dist/services/registry/schema-converter.d.ts.map +1 -0
  138. package/dist/services/registry/schema-converter.js +27 -0
  139. package/dist/services/registry/schema-converter.js.map +1 -0
  140. package/dist/services/result-collector/index.d.ts +2 -0
  141. package/dist/services/result-collector/index.d.ts.map +1 -0
  142. package/dist/services/result-collector/index.js +18 -0
  143. package/dist/services/result-collector/index.js.map +1 -0
  144. package/dist/services/result-collector/result-collector.service.d.ts +17 -0
  145. package/dist/services/result-collector/result-collector.service.d.ts.map +1 -0
  146. package/dist/services/result-collector/result-collector.service.js +92 -0
  147. package/dist/services/result-collector/result-collector.service.js.map +1 -0
  148. package/dist/services/scheduler/index.d.ts +2 -0
  149. package/dist/services/scheduler/index.d.ts.map +1 -0
  150. package/dist/services/{job-processor → scheduler}/index.js +1 -1
  151. package/dist/services/scheduler/index.js.map +1 -0
  152. package/dist/services/scheduler/scheduler.service.d.ts +17 -0
  153. package/dist/services/scheduler/scheduler.service.d.ts.map +1 -0
  154. package/dist/services/scheduler/scheduler.service.js +116 -0
  155. package/dist/services/scheduler/scheduler.service.js.map +1 -0
  156. package/dist/services/shutdown/index.d.ts +2 -0
  157. package/dist/services/shutdown/index.d.ts.map +1 -0
  158. package/dist/services/shutdown/index.js +18 -0
  159. package/dist/services/shutdown/index.js.map +1 -0
  160. package/dist/services/shutdown/shutdown.service.d.ts +8 -0
  161. package/dist/services/shutdown/shutdown.service.d.ts.map +1 -0
  162. package/dist/services/shutdown/shutdown.service.js +29 -0
  163. package/dist/services/shutdown/shutdown.service.js.map +1 -0
  164. package/dist/utils/index.d.ts +3 -1
  165. package/dist/utils/index.d.ts.map +1 -1
  166. package/dist/utils/index.js +3 -1
  167. package/dist/utils/index.js.map +1 -1
  168. package/dist/utils/naming.utils.d.ts +0 -16
  169. package/dist/utils/naming.utils.d.ts.map +1 -1
  170. package/dist/utils/naming.utils.js +0 -29
  171. package/dist/utils/naming.utils.js.map +1 -1
  172. package/package.json +19 -11
  173. package/dist/decorators/legacy.decorators.d.ts +0 -36
  174. package/dist/decorators/legacy.decorators.d.ts.map +0 -1
  175. package/dist/decorators/legacy.decorators.js +0 -61
  176. package/dist/decorators/legacy.decorators.js.map +0 -1
  177. package/dist/decorators/scaler.decorators.d.ts +0 -65
  178. package/dist/decorators/scaler.decorators.d.ts.map +0 -1
  179. package/dist/decorators/scaler.decorators.js +0 -103
  180. package/dist/decorators/scaler.decorators.js.map +0 -1
  181. package/dist/decorators/type-guards.d.ts +0 -18
  182. package/dist/decorators/type-guards.d.ts.map +0 -1
  183. package/dist/decorators/type-guards.js +0 -32
  184. package/dist/decorators/type-guards.js.map +0 -1
  185. package/dist/decorators/worker.decorators.d.ts +0 -58
  186. package/dist/decorators/worker.decorators.d.ts.map +0 -1
  187. package/dist/decorators/worker.decorators.js +0 -92
  188. package/dist/decorators/worker.decorators.js.map +0 -1
  189. package/dist/domain/interfaces/event.interfaces.d.ts +0 -71
  190. package/dist/domain/interfaces/event.interfaces.d.ts.map +0 -1
  191. package/dist/domain/interfaces/event.interfaces.js +0 -3
  192. package/dist/domain/interfaces/event.interfaces.js.map +0 -1
  193. package/dist/domain/interfaces/index-tracking.interfaces.d.ts +0 -69
  194. package/dist/domain/interfaces/index-tracking.interfaces.d.ts.map +0 -1
  195. package/dist/domain/interfaces/index-tracking.interfaces.js +0 -3
  196. package/dist/domain/interfaces/index-tracking.interfaces.js.map +0 -1
  197. package/dist/domain/interfaces/lock.interfaces.d.ts +0 -54
  198. package/dist/domain/interfaces/lock.interfaces.d.ts.map +0 -1
  199. package/dist/domain/interfaces/lock.interfaces.js.map +0 -1
  200. package/dist/domain/interfaces/process.interfaces.d.ts +0 -44
  201. package/dist/domain/interfaces/process.interfaces.d.ts.map +0 -1
  202. package/dist/domain/interfaces/process.interfaces.js +0 -3
  203. package/dist/domain/interfaces/process.interfaces.js.map +0 -1
  204. package/dist/domain/interfaces/queue.interfaces.d.ts +0 -46
  205. package/dist/domain/interfaces/queue.interfaces.d.ts.map +0 -1
  206. package/dist/domain/interfaces/queue.interfaces.js +0 -3
  207. package/dist/domain/interfaces/queue.interfaces.js.map +0 -1
  208. package/dist/domain/interfaces/scaling.interfaces.d.ts +0 -62
  209. package/dist/domain/interfaces/scaling.interfaces.d.ts.map +0 -1
  210. package/dist/domain/interfaces/scaling.interfaces.js +0 -3
  211. package/dist/domain/interfaces/scaling.interfaces.js.map +0 -1
  212. package/dist/domain/interfaces/worker.interfaces.d.ts +0 -120
  213. package/dist/domain/interfaces/worker.interfaces.d.ts.map +0 -1
  214. package/dist/domain/interfaces/worker.interfaces.js +0 -3
  215. package/dist/domain/interfaces/worker.interfaces.js.map +0 -1
  216. package/dist/services/cron-manager/cron-manager.service.d.ts +0 -199
  217. package/dist/services/cron-manager/cron-manager.service.d.ts.map +0 -1
  218. package/dist/services/cron-manager/cron-manager.service.js +0 -583
  219. package/dist/services/cron-manager/cron-manager.service.js.map +0 -1
  220. package/dist/services/cron-manager/index.d.ts +0 -2
  221. package/dist/services/cron-manager/index.d.ts.map +0 -1
  222. package/dist/services/cron-manager/index.js.map +0 -1
  223. package/dist/services/index-manager/index-manager.service.d.ts +0 -142
  224. package/dist/services/index-manager/index-manager.service.d.ts.map +0 -1
  225. package/dist/services/index-manager/index-manager.service.js +0 -325
  226. package/dist/services/index-manager/index-manager.service.js.map +0 -1
  227. package/dist/services/index-manager/index.d.ts +0 -2
  228. package/dist/services/index-manager/index.d.ts.map +0 -1
  229. package/dist/services/index-manager/index.js.map +0 -1
  230. package/dist/services/job-processor/index.d.ts +0 -2
  231. package/dist/services/job-processor/index.d.ts.map +0 -1
  232. package/dist/services/job-processor/index.js.map +0 -1
  233. package/dist/services/job-processor/job-processor.service.d.ts +0 -156
  234. package/dist/services/job-processor/job-processor.service.d.ts.map +0 -1
  235. package/dist/services/job-processor/job-processor.service.js +0 -331
  236. package/dist/services/job-processor/job-processor.service.js.map +0 -1
  237. package/dist/services/processor-discovery/decorator-discovery.service.d.ts +0 -40
  238. package/dist/services/processor-discovery/decorator-discovery.service.d.ts.map +0 -1
  239. package/dist/services/processor-discovery/decorator-discovery.service.js +0 -191
  240. package/dist/services/processor-discovery/decorator-discovery.service.js.map +0 -1
  241. package/dist/services/processor-discovery/index.d.ts +0 -6
  242. package/dist/services/processor-discovery/index.d.ts.map +0 -1
  243. package/dist/services/processor-discovery/index.js +0 -22
  244. package/dist/services/processor-discovery/index.js.map +0 -1
  245. package/dist/services/processor-discovery/processor-discovery.service.d.ts +0 -98
  246. package/dist/services/processor-discovery/processor-discovery.service.d.ts.map +0 -1
  247. package/dist/services/processor-discovery/processor-discovery.service.js +0 -258
  248. package/dist/services/processor-discovery/processor-discovery.service.js.map +0 -1
  249. package/dist/services/processor-discovery/processor-registry.d.ts +0 -58
  250. package/dist/services/processor-discovery/processor-registry.d.ts.map +0 -1
  251. package/dist/services/processor-discovery/processor-registry.js +0 -74
  252. package/dist/services/processor-discovery/processor-registry.js.map +0 -1
  253. package/dist/services/processor-discovery/scaling-registration.service.d.ts +0 -60
  254. package/dist/services/processor-discovery/scaling-registration.service.d.ts.map +0 -1
  255. package/dist/services/processor-discovery/scaling-registration.service.js +0 -261
  256. package/dist/services/processor-discovery/scaling-registration.service.js.map +0 -1
  257. package/dist/services/processor-discovery/worker-factory.service.d.ts +0 -54
  258. package/dist/services/processor-discovery/worker-factory.service.d.ts.map +0 -1
  259. package/dist/services/processor-discovery/worker-factory.service.js +0 -185
  260. package/dist/services/processor-discovery/worker-factory.service.js.map +0 -1
  261. package/dist/services/queue-bus/entity-target.d.ts +0 -58
  262. package/dist/services/queue-bus/entity-target.d.ts.map +0 -1
  263. package/dist/services/queue-bus/entity-target.js +0 -109
  264. package/dist/services/queue-bus/entity-target.js.map +0 -1
  265. package/dist/services/queue-bus/queue-bus.types.d.ts +0 -40
  266. package/dist/services/queue-bus/queue-bus.types.d.ts.map +0 -1
  267. package/dist/services/queue-bus/queue-bus.types.js +0 -3
  268. package/dist/services/queue-bus/queue-bus.types.js.map +0 -1
  269. package/dist/services/queue-bus/queue-target.d.ts +0 -61
  270. package/dist/services/queue-bus/queue-target.d.ts.map +0 -1
  271. package/dist/services/queue-bus/queue-target.js +0 -123
  272. package/dist/services/queue-bus/queue-target.js.map +0 -1
  273. package/dist/services/queue-events-manager/index.d.ts +0 -2
  274. package/dist/services/queue-events-manager/index.d.ts.map +0 -1
  275. package/dist/services/queue-events-manager/index.js.map +0 -1
  276. package/dist/services/queue-events-manager/queue-events-manager.service.d.ts +0 -120
  277. package/dist/services/queue-events-manager/queue-events-manager.service.d.ts.map +0 -1
  278. package/dist/services/queue-events-manager/queue-events-manager.service.js +0 -343
  279. package/dist/services/queue-events-manager/queue-events-manager.service.js.map +0 -1
  280. package/dist/services/queue-manager/index.d.ts +0 -2
  281. package/dist/services/queue-manager/index.d.ts.map +0 -1
  282. package/dist/services/queue-manager/index.js.map +0 -1
  283. package/dist/services/queue-manager/queue-manager.service.d.ts +0 -148
  284. package/dist/services/queue-manager/queue-manager.service.d.ts.map +0 -1
  285. package/dist/services/queue-manager/queue-manager.service.js +0 -348
  286. package/dist/services/queue-manager/queue-manager.service.js.map +0 -1
  287. package/dist/services/resource-lock/index.d.ts +0 -2
  288. package/dist/services/resource-lock/index.d.ts.map +0 -1
  289. package/dist/services/resource-lock/index.js +0 -18
  290. package/dist/services/resource-lock/index.js.map +0 -1
  291. package/dist/services/resource-lock/resource-lock.service.d.ts +0 -120
  292. package/dist/services/resource-lock/resource-lock.service.d.ts.map +0 -1
  293. package/dist/services/resource-lock/resource-lock.service.js +0 -367
  294. package/dist/services/resource-lock/resource-lock.service.js.map +0 -1
  295. package/dist/services/service-queue/index.d.ts +0 -3
  296. package/dist/services/service-queue/index.d.ts.map +0 -1
  297. package/dist/services/service-queue/index.js +0 -19
  298. package/dist/services/service-queue/index.js.map +0 -1
  299. package/dist/services/service-queue/service-queue.service.d.ts +0 -199
  300. package/dist/services/service-queue/service-queue.service.d.ts.map +0 -1
  301. package/dist/services/service-queue/service-queue.service.js +0 -617
  302. package/dist/services/service-queue/service-queue.service.js.map +0 -1
  303. package/dist/services/service-queue/service-queue.types.d.ts +0 -32
  304. package/dist/services/service-queue/service-queue.types.d.ts.map +0 -1
  305. package/dist/services/service-queue/service-queue.types.js +0 -27
  306. package/dist/services/service-queue/service-queue.types.js.map +0 -1
  307. package/dist/services/shutdown-state/index.d.ts +0 -2
  308. package/dist/services/shutdown-state/index.d.ts.map +0 -1
  309. package/dist/services/shutdown-state/index.js +0 -18
  310. package/dist/services/shutdown-state/index.js.map +0 -1
  311. package/dist/services/shutdown-state/shutdown-state.service.d.ts +0 -69
  312. package/dist/services/shutdown-state/shutdown-state.service.d.ts.map +0 -1
  313. package/dist/services/shutdown-state/shutdown-state.service.js +0 -127
  314. package/dist/services/shutdown-state/shutdown-state.service.js.map +0 -1
  315. package/dist/services/spawn-queue/index.d.ts +0 -2
  316. package/dist/services/spawn-queue/index.d.ts.map +0 -1
  317. package/dist/services/spawn-queue/index.js.map +0 -1
  318. package/dist/services/spawn-queue/spawn-queue.service.d.ts +0 -119
  319. package/dist/services/spawn-queue/spawn-queue.service.d.ts.map +0 -1
  320. package/dist/services/spawn-queue/spawn-queue.service.js +0 -273
  321. package/dist/services/spawn-queue/spawn-queue.service.js.map +0 -1
  322. package/dist/services/worker-manager/index.d.ts +0 -2
  323. package/dist/services/worker-manager/index.d.ts.map +0 -1
  324. package/dist/services/worker-manager/index.js +0 -18
  325. package/dist/services/worker-manager/index.js.map +0 -1
  326. package/dist/services/worker-manager/worker-manager.service.d.ts +0 -221
  327. package/dist/services/worker-manager/worker-manager.service.d.ts.map +0 -1
  328. package/dist/services/worker-manager/worker-manager.service.js +0 -591
  329. package/dist/services/worker-manager/worker-manager.service.js.map +0 -1
  330. package/dist/utils/helpers.d.ts +0 -5
  331. package/dist/utils/helpers.d.ts.map +0 -1
  332. package/dist/utils/helpers.js +0 -21
  333. package/dist/utils/helpers.js.map +0 -1
  334. package/dist/utils/job.utils.d.ts +0 -50
  335. package/dist/utils/job.utils.d.ts.map +0 -1
  336. package/dist/utils/job.utils.js +0 -89
  337. package/dist/utils/job.utils.js.map +0 -1
@@ -1,273 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- var SpawnQueueService_1;
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.SpawnQueueService = void 0;
20
- const common_1 = require("@nestjs/common");
21
- const bullmq_1 = require("bullmq");
22
- const ioredis_1 = __importDefault(require("ioredis"));
23
- const constants_1 = require("../constants");
24
- const worker_manager_1 = require("../worker-manager");
25
- /**
26
- * SpawnQueueService
27
- *
28
- * Replaces the cron-based / service-queue-based worker creation model
29
- * with a distributed spawn queue.
30
- *
31
- * Architecture:
32
- * - One shared BullMQ queue: `{prefix}-spawn-queue`
33
- * - EVERY pod runs a BullMQ Worker on this queue (concurrency: 1)
34
- * - When QueueEventsManager detects a job for an entity with no worker,
35
- * it enqueues a spawn-worker job here
36
- * - BullMQ distributes spawn jobs round-robin across pods
37
- * - Whichever pod picks up the job creates the entity worker locally
38
- * - Duplicate protection: before creating, check if worker already exists
39
- * (heartbeat key in Redis). If yes, skip. Race-safe because BullMQ
40
- * guarantees only ONE worker processes each job.
41
- *
42
- * Benefits over the old cron approach:
43
- * - Workers naturally distribute across all pods
44
- * - No single leader / no single point of bottleneck
45
- * - No distributed lock / leader election needed
46
- * - Reactive (spawn on demand) rather than polling
47
- *
48
- * Idle cleanup:
49
- * - Each pod runs a local interval that checks its OWN workers' idle time
50
- * - Idle workers are closed directly (no cross-pod signaling needed)
51
- */
52
- let SpawnQueueService = SpawnQueueService_1 = class SpawnQueueService {
53
- constructor(redis, config, workerManager) {
54
- this.redis = redis;
55
- this.config = config;
56
- this.workerManager = workerManager;
57
- this.logger = new common_1.Logger(SpawnQueueService_1.name);
58
- this.spawnQueue = null;
59
- this.spawnWorker = null;
60
- this.idleSweepInterval = null;
61
- /** Handler registered by ProcessorDiscoveryService */
62
- this.spawnHandler = null;
63
- /** Idle timeout per entity type (set by ProcessorDiscovery) */
64
- this.idleTimeouts = new Map();
65
- /** Reference to QueueEventsManager for hot-cache eviction on idle close */
66
- this.queueEventsManager = null;
67
- this.keyPrefix = config.keyPrefix || 'aq';
68
- this.spawnQueueName = `${this.keyPrefix}-spawn-queue`;
69
- this.defaultIdleTimeoutSeconds = 15;
70
- this.idleSweepIntervalMs = config.cronInterval ?? 5000;
71
- }
72
- /**
73
- * Set the QueueEventsManagerService reference for hot-cache eviction.
74
- * Called by ProcessorDiscoveryService to avoid circular dependency.
75
- */
76
- setQueueEventsManager(manager) {
77
- this.queueEventsManager = manager;
78
- }
79
- /**
80
- * Register the handler that creates entity workers.
81
- * Called by ProcessorDiscoveryService during init.
82
- */
83
- registerSpawnHandler(handler) {
84
- this.spawnHandler = handler;
85
- this.logger.debug('Spawn handler registered');
86
- }
87
- /**
88
- * Register idle timeout for an entity type.
89
- */
90
- registerIdleTimeout(entityType, timeoutSeconds) {
91
- this.idleTimeouts.set(entityType, timeoutSeconds);
92
- }
93
- /**
94
- * Initialize: create the spawn queue and start the spawn worker + idle sweep.
95
- */
96
- async onModuleInit() {
97
- // Create the spawn queue
98
- this.spawnQueue = new bullmq_1.Queue(this.spawnQueueName, {
99
- connection: this.redis.duplicate(),
100
- defaultJobOptions: {
101
- removeOnComplete: true,
102
- removeOnFail: 100,
103
- attempts: 2,
104
- backoff: { type: 'fixed', delay: 500 },
105
- },
106
- });
107
- // Create a BullMQ worker on this pod to consume spawn jobs
108
- this.spawnWorker = new bullmq_1.Worker(this.spawnQueueName, async (job) => {
109
- await this.handleSpawnJob(job);
110
- }, {
111
- connection: this.redis.duplicate(),
112
- concurrency: 3, // Allow a few concurrent spawns
113
- });
114
- this.spawnWorker.on('ready', () => {
115
- this.logger.log(`Spawn worker ready on this pod — listening to ${this.spawnQueueName}`);
116
- });
117
- this.spawnWorker.on('failed', (job, error) => {
118
- this.logger.error(`Spawn job ${job?.id} failed: ${error.message}`);
119
- });
120
- // Start the local idle sweep
121
- this.startIdleSweep();
122
- this.logger.log('SpawnQueueService initialized');
123
- }
124
- /**
125
- * Enqueue a spawn-worker request.
126
- * Called by QueueEventsManager when a job arrives for an entity with no worker.
127
- *
128
- * Uses deduplication: jobId = `spawn-{entityType}-{entityId}` so BullMQ
129
- * will not create a duplicate if one is already queued/active.
130
- */
131
- async requestSpawn(entityType, entityId) {
132
- if (!this.spawnQueue) {
133
- this.logger.warn('Spawn queue not initialized yet');
134
- return;
135
- }
136
- const jobId = `spawn-${entityType}-${entityId}`;
137
- try {
138
- await this.spawnQueue.add('spawn-worker', { entityType, entityId }, { jobId });
139
- this.logger.debug(`Enqueued spawn request: ${entityType}/${entityId}`);
140
- }
141
- catch (error) {
142
- // Duplicate job ID → already queued, that's fine
143
- const msg = error.message;
144
- if (msg.includes('duplicate')) {
145
- this.logger.debug(`Spawn already queued for ${entityType}/${entityId}`);
146
- }
147
- else {
148
- this.logger.error(`Failed to enqueue spawn: ${msg}`);
149
- }
150
- }
151
- }
152
- /**
153
- * Handle a spawn job picked up by this pod's worker.
154
- */
155
- async handleSpawnJob(job) {
156
- const { entityType, entityId } = job.data;
157
- this.logger.log(`Processing spawn job: ${entityType}/${entityId} (job ${job.id})`);
158
- if (!this.spawnHandler) {
159
- this.logger.warn('No spawn handler registered — cannot create worker');
160
- return;
161
- }
162
- try {
163
- await this.spawnHandler(entityType, entityId);
164
- }
165
- catch (error) {
166
- this.logger.error(`Spawn handler failed for ${entityType}/${entityId}: ${error.message}`);
167
- throw error; // Let BullMQ retry
168
- }
169
- }
170
- /**
171
- * Direct spawn — bypasses the BullMQ queue entirely.
172
- * Called by QueueEventsManagerService when it wins the atomic claim
173
- * and wants to create the worker on this pod immediately.
174
- */
175
- async handleSpawnJobDirect(entityType, entityId) {
176
- if (!this.spawnHandler) {
177
- this.logger.warn('No spawn handler registered — cannot create worker (direct)');
178
- return;
179
- }
180
- this.logger.log(`Direct spawn: ${entityType}/${entityId} (no queue round-trip)`);
181
- await this.spawnHandler(entityType, entityId);
182
- }
183
- // =========================================================================
184
- // IDLE SWEEP — runs locally on each pod
185
- // =========================================================================
186
- /**
187
- * Start the local idle sweep interval.
188
- * Periodically checks all workers on THIS pod and closes idle ones.
189
- */
190
- startIdleSweep() {
191
- this.idleSweepInterval = setInterval(async () => {
192
- try {
193
- await this.sweepIdleWorkers();
194
- }
195
- catch (error) {
196
- this.logger.error(`Idle sweep error: ${error.message}`);
197
- }
198
- }, this.idleSweepIntervalMs);
199
- this.logger.debug(`Idle sweep started (interval: ${this.idleSweepIntervalMs}ms)`);
200
- }
201
- /**
202
- * Sweep all workers on this pod, close any that are idle.
203
- */
204
- async sweepIdleWorkers() {
205
- const localWorkers = await this.workerManager.getNodeWorkers();
206
- if (localWorkers.length === 0)
207
- return;
208
- for (const workerName of localWorkers) {
209
- // Skip the spawn worker itself
210
- if (workerName.includes('spawn'))
211
- continue;
212
- // Determine idle timeout for this worker's entity type
213
- const entityType = this.extractEntityTypeFromWorkerName(workerName);
214
- const idleTimeout = entityType
215
- ? (this.idleTimeouts.get(entityType) ?? this.defaultIdleTimeoutSeconds)
216
- : this.defaultIdleTimeoutSeconds;
217
- const isIdle = await this.workerManager.isWorkerIdle(workerName, idleTimeout);
218
- if (isIdle) {
219
- const idleSeconds = await this.workerManager.getWorkerIdleSeconds(workerName);
220
- this.logger.log(`[IdleSweep] Closing idle worker: ${workerName} (idle ${idleSeconds}s >= ${idleTimeout}s threshold)`);
221
- // Evict from hot cache BEFORE closing so the next job triggers a fresh spawn
222
- if (this.queueEventsManager) {
223
- this.queueEventsManager.evictFromHotCache(workerName);
224
- }
225
- await this.workerManager.signalWorkerClose(workerName);
226
- }
227
- }
228
- }
229
- /**
230
- * Extract entity type from worker name.
231
- * Worker names follow pattern: {entityType}-{entityId}-worker
232
- * e.g., "candy-abc123-worker" → "candy"
233
- */
234
- extractEntityTypeFromWorkerName(workerName) {
235
- // Worker names from config: e.g., "candy-{uuid}-worker"
236
- // We need to match against registered entity types
237
- for (const entityType of this.idleTimeouts.keys()) {
238
- if (workerName.startsWith(`${entityType}-`)) {
239
- return entityType;
240
- }
241
- }
242
- return null;
243
- }
244
- // =========================================================================
245
- // CLEANUP
246
- // =========================================================================
247
- async onModuleDestroy() {
248
- // Stop idle sweep
249
- if (this.idleSweepInterval) {
250
- clearInterval(this.idleSweepInterval);
251
- this.idleSweepInterval = null;
252
- }
253
- // Close spawn worker
254
- if (this.spawnWorker) {
255
- await this.spawnWorker.close();
256
- this.spawnWorker = null;
257
- }
258
- // Close spawn queue
259
- if (this.spawnQueue) {
260
- await this.spawnQueue.close();
261
- this.spawnQueue = null;
262
- }
263
- this.logger.log('SpawnQueueService destroyed');
264
- }
265
- };
266
- exports.SpawnQueueService = SpawnQueueService;
267
- exports.SpawnQueueService = SpawnQueueService = SpawnQueueService_1 = __decorate([
268
- (0, common_1.Injectable)(),
269
- __param(0, (0, common_1.Inject)(constants_1.ATOMIC_QUEUES_REDIS)),
270
- __param(1, (0, common_1.Inject)(constants_1.ATOMIC_QUEUES_CONFIG)),
271
- __metadata("design:paramtypes", [ioredis_1.default, Object, worker_manager_1.WorkerManagerService])
272
- ], SpawnQueueService);
273
- //# sourceMappingURL=spawn-queue.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spawn-queue.service.js","sourceRoot":"","sources":["../../../src/services/spawn-queue/spawn-queue.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,mCAA4C;AAC5C,sDAA4B;AAE5B,4CAAyE;A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C;gBAC5C,OAAO,UAAU,CAAC;YACpB,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4EAA4E;IAC5E,UAAU;IACV,4EAA4E;IAE5E,KAAK,CAAC,eAAe;QACnB,kBAAkB;QAClB,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACtC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,CAAC;QAED,qBAAqB;QACrB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;QAED,oBAAoB;QACpB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;CACF,CAAA;AA3RY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IA0BR,WAAA,IAAA,eAAM,EAAC,+BAAmB,CAAC,CAAA;IAC3B,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;qCADwB,iBAAK,UAG1B,qCAAoB;GA5B3C,iBAAiB,CA2R7B"}
@@ -1,2 +0,0 @@
1
- export * from './worker-manager.service';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/worker-manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./worker-manager.service"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/worker-manager/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
@@ -1,221 +0,0 @@
1
- import { OnModuleInit, OnApplicationShutdown } from '@nestjs/common';
2
- import { Worker } from 'bullmq';
3
- import Redis from 'ioredis';
4
- import { IWorkerManager, IWorkerCreationOptions, IAtomicQueuesModuleConfig } from '../../domain';
5
- /**
6
- * WorkerManagerService
7
- *
8
- * Manages worker lifecycle with features from both Whatsapi and bl-blackjack-service:
9
- *
10
- * - Dynamic worker creation per entity (user message queue workers, table workers)
11
- * - Heartbeat-based liveness tracking with TTL
12
- * - Graceful shutdown via Redis pub/sub
13
- * - Node-aware worker tracking (multi-instance support)
14
- * - Automatic cleanup on application shutdown
15
- *
16
- * Architecture Notes:
17
- * - Each worker registers itself with a heartbeat TTL
18
- * - Workers subscribe to their own shutdown channel
19
- * - A cron process monitors worker health and spawns/terminates as needed
20
- * - On application shutdown, all node workers are signaled to close gracefully
21
- *
22
- * @example
23
- * ```typescript
24
- * const worker = await workerManager.createWorker({
25
- * workerName: `user-${userId}-worker`,
26
- * queueName: `user-${userId}-queue`,
27
- * processor: async (job) => {
28
- * // Process job
29
- * },
30
- * });
31
- * ```
32
- */
33
- export declare class WorkerManagerService implements IWorkerManager, OnModuleInit, OnApplicationShutdown {
34
- private readonly redis;
35
- private readonly config;
36
- private readonly logger;
37
- private readonly nodeId;
38
- private readonly workers;
39
- private readonly workerStates;
40
- private readonly heartbeatIntervals;
41
- private readonly shutdownSubscriptions;
42
- /** Tracks the last job completion time per worker (for idle detection) */
43
- private readonly lastJobCompletedAt;
44
- private subscriberClient;
45
- private readonly keyPrefix;
46
- constructor(redis: Redis, config: IAtomicQueuesModuleConfig);
47
- /**
48
- * Initialize subscriber client for pub/sub communication.
49
- */
50
- onModuleInit(): void;
51
- /**
52
- * Create a new worker with automatic lifecycle management.
53
- *
54
- * This method:
55
- * 1. Creates a BullMQ Worker
56
- * 2. Sets up heartbeat TTL tracking
57
- * 3. Subscribes to shutdown channel for graceful termination
58
- * 4. Registers lifecycle event handlers
59
- */
60
- createWorker(options: IWorkerCreationOptions): Promise<Worker>;
61
- /**
62
- * Check if a worker exists and is alive (has valid heartbeat).
63
- * Uses a global alive key for O(1) lookup instead of KEYS scan.
64
- * The alive key is maintained alongside the per-node heartbeat key.
65
- */
66
- workerExists(workerName: string): Promise<boolean>;
67
- /**
68
- * Atomically claim a worker slot using SET NX.
69
- * Returns true if this pod claimed the slot (and should create the worker).
70
- * Returns false if another pod already claimed it.
71
- * Uses a separate claim key (not the alive key) so that workerExists()
72
- * doesn't see the claim as an existing worker before creation finishes.
73
- */
74
- claimWorkerSlot(workerName: string, ttlSeconds?: number): Promise<boolean>;
75
- /**
76
- * Check if a worker exists on THIS node specifically.
77
- * Use this when you need node-local checks (e.g., for cleanup).
78
- */
79
- workerExistsOnThisNode(workerName: string): Promise<boolean>;
80
- /**
81
- * Get all running workers for the current node.
82
- */
83
- getNodeWorkers(): Promise<string[]>;
84
- /**
85
- * Get all running workers across all nodes.
86
- */
87
- getAllWorkers(): Promise<string[]>;
88
- /**
89
- * Get all workers for a specific entity.
90
- * Uses the worker heartbeat TTL keys as the single source of truth.
91
- * Worker names follow the pattern: {entityId}-worker
92
- */
93
- getEntityWorkers(entityType: string, entityId: string): Promise<string[]>;
94
- /**
95
- * Signal a worker to close gracefully via pub/sub.
96
- */
97
- signalWorkerClose(workerName: string): Promise<void>;
98
- /**
99
- * Signal all workers on current node to close.
100
- */
101
- signalNodeWorkersClose(): Promise<void>;
102
- /**
103
- * Close all workers managed by this instance.
104
- * This is the public API for external callers to gracefully shutdown workers.
105
- */
106
- closeAllWorkers(timeoutMs?: number): Promise<void>;
107
- /**
108
- * Wait for all node workers to close with timeout.
109
- */
110
- waitForWorkersToClose(timeoutMs?: number): Promise<void>;
111
- /**
112
- * Reset worker heartbeat TTL.
113
- */
114
- resetWorkerHeartbeat(workerName: string, ttlSeconds?: number): Promise<void>;
115
- /**
116
- * Remove worker heartbeat (mark as dead).
117
- */
118
- removeWorkerHeartbeat(workerName: string): Promise<void>;
119
- /**
120
- * Mark that a worker has completed a job (resets idle counter).
121
- * Called internally when job completes.
122
- */
123
- markWorkerActive(workerName: string): void;
124
- /**
125
- * Get the idle seconds counter for a worker from Redis.
126
- * This is incremented by the heartbeat and reset when a job completes.
127
- */
128
- getWorkerIdleSeconds(workerName: string): Promise<number>;
129
- /**
130
- * Reset the idle counter for a worker (called when job completes).
131
- */
132
- resetWorkerIdleCounter(workerName: string): Promise<void>;
133
- /**
134
- * Increment the idle counter for a worker (called by heartbeat).
135
- * Returns the new idle seconds value.
136
- */
137
- incrementWorkerIdleCounter(workerName: string, incrementBy?: number): Promise<number>;
138
- /**
139
- * Remove the idle counter for a worker (cleanup).
140
- */
141
- removeWorkerIdleCounter(workerName: string): Promise<void>;
142
- /**
143
- * Check if a worker is idle based on threshold.
144
- * @param workerName - Worker name
145
- * @param thresholdSeconds - Idle threshold in seconds (default: 15)
146
- */
147
- isWorkerIdle(workerName: string, thresholdSeconds?: number): Promise<boolean>;
148
- /**
149
- * Get the Redis key for a worker's idle counter.
150
- */
151
- private getWorkerIdleKey;
152
- /**
153
- * Get the node ID for this instance.
154
- */
155
- getNodeId(): string;
156
- /**
157
- * Index a worker for an entity (for entity-based tracking).
158
- */
159
- indexEntityWorker(entityType: string, entityId: string, workerId: string, ttlSeconds?: number): Promise<void>;
160
- /**
161
- * Remove entity worker index.
162
- */
163
- removeEntityWorkerIndex(entityType: string, entityId: string, workerId: string): Promise<void>;
164
- /**
165
- * Get subscriber client for pub/sub operations.
166
- */
167
- getSubscriberClient(): Redis;
168
- /**
169
- * Graceful shutdown on application termination.
170
- */
171
- onApplicationShutdown(): Promise<void>;
172
- /**
173
- * Generate a unique node ID for this instance.
174
- */
175
- private generateNodeId;
176
- /**
177
- * Create a subscriber client for pub/sub.
178
- */
179
- private createSubscriberClient;
180
- /**
181
- * Get the Redis key for a worker's heartbeat (per-node).
182
- */
183
- private getWorkerKey;
184
- /**
185
- * Get the global alive key for O(1) worker existence check.
186
- * This key has the same TTL as the per-node heartbeat and is
187
- * refreshed in the same pipeline. It replaces the O(N) KEYS scan
188
- * with a single O(1) EXISTS call.
189
- */
190
- private getGlobalAliveKey;
191
- /**
192
- * Get the shutdown channel for a worker.
193
- */
194
- private getWorkerShutdownChannel;
195
- /**
196
- * Merge worker config with defaults.
197
- */
198
- private mergeWorkerConfig;
199
- /**
200
- * Set up heartbeat interval for a worker.
201
- * Also increments idle counter on each heartbeat tick.
202
- */
203
- private setupHeartbeat;
204
- /**
205
- * Subscribe to shutdown channel for graceful termination.
206
- */
207
- private subscribeToShutdown;
208
- /**
209
- * Close a worker and clean up resources.
210
- */
211
- private closeWorker;
212
- /**
213
- * Register event handlers for a worker.
214
- */
215
- private registerWorkerEvents;
216
- /**
217
- * Sleep utility.
218
- */
219
- private sleep;
220
- }
221
- //# sourceMappingURL=worker-manager.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker-manager.service.d.ts","sourceRoot":"","sources":["../../../src/services/worker-manager/worker-manager.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,qBAAqB,EAEtB,MAAM,g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