@versori/run 0.5.0-alpha.5 → 0.5.0-alpha.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA+I7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AASzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8M7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
@@ -26,8 +26,43 @@ function compileSchedule(ctx, trigger, signal) {
26
26
  const orgId = Deno.env.get(envVarOrgId) || 'example-org';
27
27
  const client = ctx.platformApi;
28
28
  ctx.cronRegistry.set(trigger.id, trigger.schedule);
29
- async function handleSchedule(_req, res, span) {
29
+ async function handleSchedule(req, res, span) {
30
30
  try {
31
+ // run for a single activation
32
+ const activationId = req.params.activationId;
33
+ if (activationId) {
34
+ const { data: activation } = await client.getActivation({
35
+ path: {
36
+ organisation_id: ctx.organisationId,
37
+ environment_id: environmentId,
38
+ activation_id: activationId,
39
+ },
40
+ throwOnError: false,
41
+ });
42
+ if (!activation) {
43
+ res.status(412).json({
44
+ status: 'error',
45
+ message: `No activation found for ID: ${activationId}`,
46
+ });
47
+ return;
48
+ }
49
+ const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
50
+ span.setAttribute('execution.id', executionCtx.executionId);
51
+ await sendTaskStartEvent(trigger.id, executionCtx, span);
52
+ try {
53
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activationId}`);
54
+ subscriber.next(executionCtx);
55
+ }
56
+ catch (error) {
57
+ executionCtx.log.error('execution error inside schedule', { error });
58
+ }
59
+ res.status(200).json({
60
+ status: 'triggered',
61
+ executionId: executionCtx.executionId,
62
+ });
63
+ return;
64
+ }
65
+ // run for static activation only
31
66
  if (trigger.activationPredicate === undefined) {
32
67
  const { data: activation } = await client.listActivations({
33
68
  path: {
@@ -61,6 +96,7 @@ function compileSchedule(ctx, trigger, signal) {
61
96
  });
62
97
  return;
63
98
  }
99
+ // run for all activations
64
100
  const { data: activations } = await client.listActivations({
65
101
  path: {
66
102
  organisation_id: ctx.organisationId,
@@ -81,6 +117,7 @@ function compileSchedule(ctx, trigger, signal) {
81
117
  activations.forEach((activation) => {
82
118
  const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
83
119
  try {
120
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activation.id}`);
84
121
  subscriber.next(executionCtx);
85
122
  }
86
123
  catch (error) {
@@ -109,6 +146,22 @@ function compileSchedule(ctx, trigger, signal) {
109
146
  span.end();
110
147
  });
111
148
  });
149
+ ctx.cronRouter.post(`/cron/${trigger.id}/activations/:activationId`, async (req, res) => {
150
+ await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
151
+ span.setAttribute('task.id', trigger.id);
152
+ span.setAttribute('activation.id', req.params.activationId);
153
+ span.setAttribute('task.type', 'schedule');
154
+ span.setAttribute('type', 'task');
155
+ span.setAttribute('schedule', trigger.schedule);
156
+ span.setAttribute('project.id', projectId);
157
+ span.setAttribute('environment.id', environmentId);
158
+ span.setAttribute('environment.name', environmentName);
159
+ span.setAttribute('org.id', orgId);
160
+ span.setAttribute('workflow.id', trigger.id);
161
+ await handleSchedule(req, res, span);
162
+ span.end();
163
+ });
164
+ });
112
165
  function cleanup() {
113
166
  ctx.log.debug('scheduler trigger stopped');
114
167
  subscriber.complete();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versori/run",
3
- "version": "0.5.0-alpha.5",
3
+ "version": "0.5.0-alpha.6",
4
4
  "description": "Versori Run",
5
5
  "homepage": "https://github.com/versori/versori-run#readme",
6
6
  "repository": {
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA+I7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AASzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8M7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
@@ -29,8 +29,43 @@ function compileSchedule(ctx, trigger, signal) {
29
29
  const orgId = Deno.env.get(constants_js_1.envVarOrgId) || 'example-org';
30
30
  const client = ctx.platformApi;
31
31
  ctx.cronRegistry.set(trigger.id, trigger.schedule);
32
- async function handleSchedule(_req, res, span) {
32
+ async function handleSchedule(req, res, span) {
33
33
  try {
34
+ // run for a single activation
35
+ const activationId = req.params.activationId;
36
+ if (activationId) {
37
+ const { data: activation } = await client.getActivation({
38
+ path: {
39
+ organisation_id: ctx.organisationId,
40
+ environment_id: environmentId,
41
+ activation_id: activationId,
42
+ },
43
+ throwOnError: false,
44
+ });
45
+ if (!activation) {
46
+ res.status(412).json({
47
+ status: 'error',
48
+ message: `No activation found for ID: ${activationId}`,
49
+ });
50
+ return;
51
+ }
52
+ const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
53
+ span.setAttribute('execution.id', executionCtx.executionId);
54
+ await (0, supervisor_js_1.sendTaskStartEvent)(trigger.id, executionCtx, span);
55
+ try {
56
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activationId}`);
57
+ subscriber.next(executionCtx);
58
+ }
59
+ catch (error) {
60
+ executionCtx.log.error('execution error inside schedule', { error });
61
+ }
62
+ res.status(200).json({
63
+ status: 'triggered',
64
+ executionId: executionCtx.executionId,
65
+ });
66
+ return;
67
+ }
68
+ // run for static activation only
34
69
  if (trigger.activationPredicate === undefined) {
35
70
  const { data: activation } = await client.listActivations({
36
71
  path: {
@@ -64,6 +99,7 @@ function compileSchedule(ctx, trigger, signal) {
64
99
  });
65
100
  return;
66
101
  }
102
+ // run for all activations
67
103
  const { data: activations } = await client.listActivations({
68
104
  path: {
69
105
  organisation_id: ctx.organisationId,
@@ -84,6 +120,7 @@ function compileSchedule(ctx, trigger, signal) {
84
120
  activations.forEach((activation) => {
85
121
  const executionCtx = ctx.contextProvider.create(activation, {}, { workflowId: trigger.id });
86
122
  try {
123
+ ctx.log.info(`Running schedule ${trigger.id} for activation ${activation.id}`);
87
124
  subscriber.next(executionCtx);
88
125
  }
89
126
  catch (error) {
@@ -112,6 +149,22 @@ function compileSchedule(ctx, trigger, signal) {
112
149
  span.end();
113
150
  });
114
151
  });
152
+ ctx.cronRouter.post(`/cron/${trigger.id}/activations/:activationId`, async (req, res) => {
153
+ await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
154
+ span.setAttribute('task.id', trigger.id);
155
+ span.setAttribute('activation.id', req.params.activationId);
156
+ span.setAttribute('task.type', 'schedule');
157
+ span.setAttribute('type', 'task');
158
+ span.setAttribute('schedule', trigger.schedule);
159
+ span.setAttribute('project.id', projectId);
160
+ span.setAttribute('environment.id', environmentId);
161
+ span.setAttribute('environment.name', environmentName);
162
+ span.setAttribute('org.id', orgId);
163
+ span.setAttribute('workflow.id', trigger.id);
164
+ await handleSchedule(req, res, span);
165
+ span.end();
166
+ });
167
+ });
115
168
  function cleanup() {
116
169
  ctx.log.debug('scheduler trigger stopped');
117
170
  subscriber.complete();