@trigger.dev/core 0.0.0-v3-prerelease-20240424101411 → 0.0.0-v3-prerelease-20240425102616

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.
@@ -4,8 +4,8 @@ export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.mj
4
4
  import { p as TaskRunExecution, T as TaskRunExecutionResult } from '../../manager-M9GLDnhJ.mjs';
5
5
  export { R as RuntimeManager } from '../../manager-M9GLDnhJ.mjs';
6
6
  import { B as BackgroundWorkerProperties, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../messages-AriaDDm0.mjs';
7
- import { d as TriggerTracer, g as Config, y as ProjectConfig, w as HandleErrorFunction, c as TaskMetadataWithFunctions, C as Clock, a as ClockTime, b as TaskCatalog } from '../../catalog-A-D3UC6S.mjs';
8
- export { O as OtelTaskLogger, z as logLevels } from '../../catalog-A-D3UC6S.mjs';
7
+ import { d as TriggerTracer, g as Config, z as ProjectConfig, x as HandleErrorFunction, c as TaskMetadataWithFunctions, C as Clock, a as ClockTime, b as TaskCatalog } from '../../catalog-PA64uhhi.mjs';
8
+ export { O as OtelTaskLogger, A as logLevels } from '../../catalog-PA64uhhi.mjs';
9
9
  import { PreciseDate } from '@google-cloud/precise-date';
10
10
  import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
11
11
  import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
@@ -4,8 +4,8 @@ export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.js
4
4
  import { p as TaskRunExecution, T as TaskRunExecutionResult } from '../../manager-M9GLDnhJ.js';
5
5
  export { R as RuntimeManager } from '../../manager-M9GLDnhJ.js';
6
6
  import { B as BackgroundWorkerProperties, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../messages-AriaDDm0.js';
7
- import { d as TriggerTracer, g as Config, y as ProjectConfig, w as HandleErrorFunction, c as TaskMetadataWithFunctions, C as Clock, a as ClockTime, b as TaskCatalog } from '../../catalog-TAZd4-TP.js';
8
- export { O as OtelTaskLogger, z as logLevels } from '../../catalog-TAZd4-TP.js';
7
+ import { d as TriggerTracer, g as Config, z as ProjectConfig, x as HandleErrorFunction, c as TaskMetadataWithFunctions, C as Clock, a as ClockTime, b as TaskCatalog } from '../../catalog-KJXg8k3W.js';
8
+ export { O as OtelTaskLogger, A as logLevels } from '../../catalog-KJXg8k3W.js';
9
9
  import { PreciseDate } from '@google-cloud/precise-date';
10
10
  import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
11
11
  import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var api = require('@opentelemetry/api');
4
- require('path');
5
4
  var apiLogs = require('@opentelemetry/api-logs');
6
5
  var exporterLogsOtlpHttp = require('@opentelemetry/exporter-logs-otlp-http');
7
6
  var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
@@ -44,6 +43,8 @@ var __privateMethod = (obj, member, method) => {
44
43
  __accessCheck(obj, member, "access private method");
45
44
  return method;
46
45
  };
46
+
47
+ // src/v3/errors.ts
47
48
  function parseError(error) {
48
49
  if (error instanceof Error) {
49
50
  return {
@@ -1974,11 +1975,18 @@ function accessoryAttributes(accessory) {
1974
1975
  __name(accessoryAttributes, "accessoryAttributes");
1975
1976
 
1976
1977
  // src/v3/workers/taskExecutor.ts
1977
- var _callRun, callRun_fn, _callTaskInit, callTaskInit_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
1978
+ var _callRun, callRun_fn, _callInitFunctions, callInitFunctions_fn, _callConfigInit, callConfigInit_fn, _callOnSuccessFunctions, callOnSuccessFunctions_fn, _callOnSuccessFunction, callOnSuccessFunction_fn, _callOnFailureFunctions, callOnFailureFunctions_fn, _callOnFailureFunction, callOnFailureFunction_fn, _callOnStartFunctions, callOnStartFunctions_fn, _callOnStartFunction, callOnStartFunction_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
1978
1979
  var _TaskExecutor = class _TaskExecutor {
1979
1980
  constructor(task, options) {
1980
1981
  __privateAdd(this, _callRun);
1981
- __privateAdd(this, _callTaskInit);
1982
+ __privateAdd(this, _callInitFunctions);
1983
+ __privateAdd(this, _callConfigInit);
1984
+ __privateAdd(this, _callOnSuccessFunctions);
1985
+ __privateAdd(this, _callOnSuccessFunction);
1986
+ __privateAdd(this, _callOnFailureFunctions);
1987
+ __privateAdd(this, _callOnFailureFunction);
1988
+ __privateAdd(this, _callOnStartFunctions);
1989
+ __privateAdd(this, _callOnStartFunction);
1982
1990
  __privateAdd(this, _callTaskCleanup);
1983
1991
  __privateAdd(this, _handleError);
1984
1992
  this.task = task;
@@ -2012,8 +2020,12 @@ var _TaskExecutor = class _TaskExecutor {
2012
2020
  try {
2013
2021
  const payloadPacket = await conditionallyImportPacket(originalPacket, this._tracer);
2014
2022
  parsedPayload = await parsePacket(payloadPacket);
2015
- initOutput = await __privateMethod(this, _callTaskInit, callTaskInit_fn).call(this, parsedPayload, ctx);
2023
+ if (execution.attempt.number === 1) {
2024
+ await __privateMethod(this, _callOnStartFunctions, callOnStartFunctions_fn).call(this, parsedPayload, ctx);
2025
+ }
2026
+ initOutput = await __privateMethod(this, _callInitFunctions, callInitFunctions_fn).call(this, parsedPayload, ctx);
2016
2027
  const output = await __privateMethod(this, _callRun, callRun_fn).call(this, parsedPayload, ctx, initOutput);
2028
+ await __privateMethod(this, _callOnSuccessFunctions, callOnSuccessFunctions_fn).call(this, parsedPayload, output, ctx, initOutput);
2017
2029
  try {
2018
2030
  const stringifiedOutput = await stringifyIO(output);
2019
2031
  const finalOutput = await conditionallyExportPacket(stringifiedOutput, `${execution.attempt.id}/output`, this._tracer);
@@ -2043,6 +2055,9 @@ var _TaskExecutor = class _TaskExecutor {
2043
2055
  try {
2044
2056
  const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
2045
2057
  recordSpanException(span, handleErrorResult.error ?? runError);
2058
+ if (handleErrorResult.status !== "retry") {
2059
+ await __privateMethod(this, _callOnFailureFunctions, callOnFailureFunctions_fn).call(this, parsedPayload, handleErrorResult.error ?? runError, ctx, initOutput);
2060
+ }
2046
2061
  return {
2047
2062
  id: execution.run.id,
2048
2063
  ok: false,
@@ -2106,8 +2121,9 @@ callRun_fn = /* @__PURE__ */ __name(async function(payload, ctx, init) {
2106
2121
  })
2107
2122
  });
2108
2123
  }, "#callRun");
2109
- _callTaskInit = new WeakSet();
2110
- callTaskInit_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2124
+ _callInitFunctions = new WeakSet();
2125
+ callInitFunctions_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2126
+ await __privateMethod(this, _callConfigInit, callConfigInit_fn).call(this, payload1, ctx1);
2111
2127
  const initFn = this.task.fns.init;
2112
2128
  if (!initFn) {
2113
2129
  return {};
@@ -2116,23 +2132,114 @@ callTaskInit_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2116
2132
  return await initFn(payload1, {
2117
2133
  ctx: ctx1
2118
2134
  });
2135
+ }, {
2136
+ attributes: {
2137
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2138
+ }
2139
+ });
2140
+ }, "#callInitFunctions");
2141
+ _callConfigInit = new WeakSet();
2142
+ callConfigInit_fn = /* @__PURE__ */ __name(async function(payload2, ctx2) {
2143
+ const initFn = this._importedConfig?.init;
2144
+ if (!initFn) {
2145
+ return {};
2146
+ }
2147
+ return this._tracer.startActiveSpan("config.init", async (span) => {
2148
+ return await initFn(payload2, {
2149
+ ctx: ctx2
2150
+ });
2151
+ }, {
2152
+ attributes: {
2153
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2154
+ }
2119
2155
  });
2120
- }, "#callTaskInit");
2156
+ }, "#callConfigInit");
2157
+ _callOnSuccessFunctions = new WeakSet();
2158
+ callOnSuccessFunctions_fn = /* @__PURE__ */ __name(async function(payload3, output, ctx3, initOutput) {
2159
+ await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this.task.fns.onSuccess, "task.onSuccess", payload3, output, ctx3, initOutput);
2160
+ await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this._importedConfig?.onSuccess, "config.onSuccess", payload3, output, ctx3, initOutput);
2161
+ }, "#callOnSuccessFunctions");
2162
+ _callOnSuccessFunction = new WeakSet();
2163
+ callOnSuccessFunction_fn = /* @__PURE__ */ __name(async function(onSuccessFn, name, payload4, output1, ctx4, initOutput1) {
2164
+ if (!onSuccessFn) {
2165
+ return;
2166
+ }
2167
+ try {
2168
+ await this._tracer.startActiveSpan(name, async (span) => {
2169
+ return await onSuccessFn(payload4, output1, {
2170
+ ctx: ctx4,
2171
+ init: initOutput1
2172
+ });
2173
+ }, {
2174
+ attributes: {
2175
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2176
+ }
2177
+ });
2178
+ } catch {
2179
+ }
2180
+ }, "#callOnSuccessFunction");
2181
+ _callOnFailureFunctions = new WeakSet();
2182
+ callOnFailureFunctions_fn = /* @__PURE__ */ __name(async function(payload5, error, ctx5, initOutput2) {
2183
+ await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this.task.fns.onFailure, "task.onFailure", payload5, error, ctx5, initOutput2);
2184
+ await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this._importedConfig?.onFailure, "config.onFailure", payload5, error, ctx5, initOutput2);
2185
+ }, "#callOnFailureFunctions");
2186
+ _callOnFailureFunction = new WeakSet();
2187
+ callOnFailureFunction_fn = /* @__PURE__ */ __name(async function(onFailureFn, name1, payload6, error1, ctx6, initOutput3) {
2188
+ if (!onFailureFn) {
2189
+ return;
2190
+ }
2191
+ try {
2192
+ return await this._tracer.startActiveSpan(name1, async (span) => {
2193
+ return await onFailureFn(payload6, error1, {
2194
+ ctx: ctx6,
2195
+ init: initOutput3
2196
+ });
2197
+ }, {
2198
+ attributes: {
2199
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2200
+ }
2201
+ });
2202
+ } catch (e) {
2203
+ }
2204
+ }, "#callOnFailureFunction");
2205
+ _callOnStartFunctions = new WeakSet();
2206
+ callOnStartFunctions_fn = /* @__PURE__ */ __name(async function(payload7, ctx7) {
2207
+ await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this._importedConfig?.onStart, "config.onStart", payload7, ctx7, {});
2208
+ await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this.task.fns.onStart, "task.onStart", payload7, ctx7, {});
2209
+ }, "#callOnStartFunctions");
2210
+ _callOnStartFunction = new WeakSet();
2211
+ callOnStartFunction_fn = /* @__PURE__ */ __name(async function(onStartFn, name2, payload8, ctx8, initOutput4) {
2212
+ if (!onStartFn) {
2213
+ return;
2214
+ }
2215
+ try {
2216
+ await this._tracer.startActiveSpan(name2, async (span) => {
2217
+ return await onStartFn(payload8, {
2218
+ ctx: ctx8
2219
+ });
2220
+ }, {
2221
+ attributes: {
2222
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2223
+ }
2224
+ });
2225
+ } catch {
2226
+ }
2227
+ }, "#callOnStartFunction");
2121
2228
  _callTaskCleanup = new WeakSet();
2122
- callTaskCleanup_fn = /* @__PURE__ */ __name(async function(payload2, ctx2, init1) {
2229
+ callTaskCleanup_fn = /* @__PURE__ */ __name(async function(payload9, ctx9, init1) {
2123
2230
  const cleanupFn = this.task.fns.cleanup;
2124
2231
  if (!cleanupFn) {
2125
2232
  return;
2126
2233
  }
2127
2234
  return this._tracer.startActiveSpan("cleanup", async (span) => {
2128
- return await cleanupFn(payload2, {
2129
- ctx: ctx2,
2235
+ return await cleanupFn(payload9, {
2236
+ ctx: ctx9,
2130
2237
  init: init1
2131
2238
  });
2132
2239
  });
2133
2240
  }, "#callTaskCleanup");
2134
2241
  _handleError = new WeakSet();
2135
- handleError_fn = /* @__PURE__ */ __name(async function(execution, error, payload3, ctx3) {
2242
+ handleError_fn = /* @__PURE__ */ __name(async function(execution, error2, payload10, ctx10) {
2136
2243
  const retriesConfig = this._importedConfig?.retries ?? this._config.retries;
2137
2244
  const retry = this.task.retry ?? retriesConfig?.default;
2138
2245
  if (!retry) {
@@ -2147,13 +2254,13 @@ handleError_fn = /* @__PURE__ */ __name(async function(execution, error, payload
2147
2254
  };
2148
2255
  }
2149
2256
  return this._tracer.startActiveSpan("handleError()", async (span) => {
2150
- const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload3, error, {
2151
- ctx: ctx3,
2257
+ const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload10, error2, {
2258
+ ctx: ctx10,
2152
2259
  retry,
2153
2260
  retryDelayInMs: delay,
2154
2261
  retryAt: delay ? new Date(Date.now() + delay) : void 0
2155
- }) : this._importedConfig ? await this._handleErrorFn?.(payload3, error, {
2156
- ctx: ctx3,
2262
+ }) : this._importedConfig ? await this._handleErrorFn?.(payload10, error2, {
2263
+ ctx: ctx10,
2157
2264
  retry,
2158
2265
  retryDelayInMs: delay,
2159
2266
  retryAt: delay ? new Date(Date.now() + delay) : void 0