@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.
@@ -1,5 +1,4 @@
1
1
  import { SpanStatusCode, DiagLogLevel, diag, DiagConsoleLogger, propagation, context, SpanKind } from '@opentelemetry/api';
2
- import 'node:path';
3
2
  import { logs, SeverityNumber } from '@opentelemetry/api-logs';
4
3
  import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
5
4
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
@@ -38,6 +37,8 @@ var __privateMethod = (obj, member, method) => {
38
37
  __accessCheck(obj, member, "access private method");
39
38
  return method;
40
39
  };
40
+
41
+ // src/v3/errors.ts
41
42
  function parseError(error) {
42
43
  if (error instanceof Error) {
43
44
  return {
@@ -1968,11 +1969,18 @@ function accessoryAttributes(accessory) {
1968
1969
  __name(accessoryAttributes, "accessoryAttributes");
1969
1970
 
1970
1971
  // src/v3/workers/taskExecutor.ts
1971
- var _callRun, callRun_fn, _callTaskInit, callTaskInit_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
1972
+ 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;
1972
1973
  var _TaskExecutor = class _TaskExecutor {
1973
1974
  constructor(task, options) {
1974
1975
  __privateAdd(this, _callRun);
1975
- __privateAdd(this, _callTaskInit);
1976
+ __privateAdd(this, _callInitFunctions);
1977
+ __privateAdd(this, _callConfigInit);
1978
+ __privateAdd(this, _callOnSuccessFunctions);
1979
+ __privateAdd(this, _callOnSuccessFunction);
1980
+ __privateAdd(this, _callOnFailureFunctions);
1981
+ __privateAdd(this, _callOnFailureFunction);
1982
+ __privateAdd(this, _callOnStartFunctions);
1983
+ __privateAdd(this, _callOnStartFunction);
1976
1984
  __privateAdd(this, _callTaskCleanup);
1977
1985
  __privateAdd(this, _handleError);
1978
1986
  this.task = task;
@@ -2006,8 +2014,12 @@ var _TaskExecutor = class _TaskExecutor {
2006
2014
  try {
2007
2015
  const payloadPacket = await conditionallyImportPacket(originalPacket, this._tracer);
2008
2016
  parsedPayload = await parsePacket(payloadPacket);
2009
- initOutput = await __privateMethod(this, _callTaskInit, callTaskInit_fn).call(this, parsedPayload, ctx);
2017
+ if (execution.attempt.number === 1) {
2018
+ await __privateMethod(this, _callOnStartFunctions, callOnStartFunctions_fn).call(this, parsedPayload, ctx);
2019
+ }
2020
+ initOutput = await __privateMethod(this, _callInitFunctions, callInitFunctions_fn).call(this, parsedPayload, ctx);
2010
2021
  const output = await __privateMethod(this, _callRun, callRun_fn).call(this, parsedPayload, ctx, initOutput);
2022
+ await __privateMethod(this, _callOnSuccessFunctions, callOnSuccessFunctions_fn).call(this, parsedPayload, output, ctx, initOutput);
2011
2023
  try {
2012
2024
  const stringifiedOutput = await stringifyIO(output);
2013
2025
  const finalOutput = await conditionallyExportPacket(stringifiedOutput, `${execution.attempt.id}/output`, this._tracer);
@@ -2037,6 +2049,9 @@ var _TaskExecutor = class _TaskExecutor {
2037
2049
  try {
2038
2050
  const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
2039
2051
  recordSpanException(span, handleErrorResult.error ?? runError);
2052
+ if (handleErrorResult.status !== "retry") {
2053
+ await __privateMethod(this, _callOnFailureFunctions, callOnFailureFunctions_fn).call(this, parsedPayload, handleErrorResult.error ?? runError, ctx, initOutput);
2054
+ }
2040
2055
  return {
2041
2056
  id: execution.run.id,
2042
2057
  ok: false,
@@ -2100,8 +2115,9 @@ callRun_fn = /* @__PURE__ */ __name(async function(payload, ctx, init) {
2100
2115
  })
2101
2116
  });
2102
2117
  }, "#callRun");
2103
- _callTaskInit = new WeakSet();
2104
- callTaskInit_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2118
+ _callInitFunctions = new WeakSet();
2119
+ callInitFunctions_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2120
+ await __privateMethod(this, _callConfigInit, callConfigInit_fn).call(this, payload1, ctx1);
2105
2121
  const initFn = this.task.fns.init;
2106
2122
  if (!initFn) {
2107
2123
  return {};
@@ -2110,23 +2126,114 @@ callTaskInit_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
2110
2126
  return await initFn(payload1, {
2111
2127
  ctx: ctx1
2112
2128
  });
2129
+ }, {
2130
+ attributes: {
2131
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2132
+ }
2133
+ });
2134
+ }, "#callInitFunctions");
2135
+ _callConfigInit = new WeakSet();
2136
+ callConfigInit_fn = /* @__PURE__ */ __name(async function(payload2, ctx2) {
2137
+ const initFn = this._importedConfig?.init;
2138
+ if (!initFn) {
2139
+ return {};
2140
+ }
2141
+ return this._tracer.startActiveSpan("config.init", async (span) => {
2142
+ return await initFn(payload2, {
2143
+ ctx: ctx2
2144
+ });
2145
+ }, {
2146
+ attributes: {
2147
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2148
+ }
2113
2149
  });
2114
- }, "#callTaskInit");
2150
+ }, "#callConfigInit");
2151
+ _callOnSuccessFunctions = new WeakSet();
2152
+ callOnSuccessFunctions_fn = /* @__PURE__ */ __name(async function(payload3, output, ctx3, initOutput) {
2153
+ await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this.task.fns.onSuccess, "task.onSuccess", payload3, output, ctx3, initOutput);
2154
+ await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this._importedConfig?.onSuccess, "config.onSuccess", payload3, output, ctx3, initOutput);
2155
+ }, "#callOnSuccessFunctions");
2156
+ _callOnSuccessFunction = new WeakSet();
2157
+ callOnSuccessFunction_fn = /* @__PURE__ */ __name(async function(onSuccessFn, name, payload4, output1, ctx4, initOutput1) {
2158
+ if (!onSuccessFn) {
2159
+ return;
2160
+ }
2161
+ try {
2162
+ await this._tracer.startActiveSpan(name, async (span) => {
2163
+ return await onSuccessFn(payload4, output1, {
2164
+ ctx: ctx4,
2165
+ init: initOutput1
2166
+ });
2167
+ }, {
2168
+ attributes: {
2169
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2170
+ }
2171
+ });
2172
+ } catch {
2173
+ }
2174
+ }, "#callOnSuccessFunction");
2175
+ _callOnFailureFunctions = new WeakSet();
2176
+ callOnFailureFunctions_fn = /* @__PURE__ */ __name(async function(payload5, error, ctx5, initOutput2) {
2177
+ await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this.task.fns.onFailure, "task.onFailure", payload5, error, ctx5, initOutput2);
2178
+ await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this._importedConfig?.onFailure, "config.onFailure", payload5, error, ctx5, initOutput2);
2179
+ }, "#callOnFailureFunctions");
2180
+ _callOnFailureFunction = new WeakSet();
2181
+ callOnFailureFunction_fn = /* @__PURE__ */ __name(async function(onFailureFn, name1, payload6, error1, ctx6, initOutput3) {
2182
+ if (!onFailureFn) {
2183
+ return;
2184
+ }
2185
+ try {
2186
+ return await this._tracer.startActiveSpan(name1, async (span) => {
2187
+ return await onFailureFn(payload6, error1, {
2188
+ ctx: ctx6,
2189
+ init: initOutput3
2190
+ });
2191
+ }, {
2192
+ attributes: {
2193
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2194
+ }
2195
+ });
2196
+ } catch (e) {
2197
+ }
2198
+ }, "#callOnFailureFunction");
2199
+ _callOnStartFunctions = new WeakSet();
2200
+ callOnStartFunctions_fn = /* @__PURE__ */ __name(async function(payload7, ctx7) {
2201
+ await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this._importedConfig?.onStart, "config.onStart", payload7, ctx7, {});
2202
+ await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this.task.fns.onStart, "task.onStart", payload7, ctx7, {});
2203
+ }, "#callOnStartFunctions");
2204
+ _callOnStartFunction = new WeakSet();
2205
+ callOnStartFunction_fn = /* @__PURE__ */ __name(async function(onStartFn, name2, payload8, ctx8, initOutput4) {
2206
+ if (!onStartFn) {
2207
+ return;
2208
+ }
2209
+ try {
2210
+ await this._tracer.startActiveSpan(name2, async (span) => {
2211
+ return await onStartFn(payload8, {
2212
+ ctx: ctx8
2213
+ });
2214
+ }, {
2215
+ attributes: {
2216
+ [SemanticInternalAttributes.STYLE_ICON]: "function"
2217
+ }
2218
+ });
2219
+ } catch {
2220
+ }
2221
+ }, "#callOnStartFunction");
2115
2222
  _callTaskCleanup = new WeakSet();
2116
- callTaskCleanup_fn = /* @__PURE__ */ __name(async function(payload2, ctx2, init1) {
2223
+ callTaskCleanup_fn = /* @__PURE__ */ __name(async function(payload9, ctx9, init1) {
2117
2224
  const cleanupFn = this.task.fns.cleanup;
2118
2225
  if (!cleanupFn) {
2119
2226
  return;
2120
2227
  }
2121
2228
  return this._tracer.startActiveSpan("cleanup", async (span) => {
2122
- return await cleanupFn(payload2, {
2123
- ctx: ctx2,
2229
+ return await cleanupFn(payload9, {
2230
+ ctx: ctx9,
2124
2231
  init: init1
2125
2232
  });
2126
2233
  });
2127
2234
  }, "#callTaskCleanup");
2128
2235
  _handleError = new WeakSet();
2129
- handleError_fn = /* @__PURE__ */ __name(async function(execution, error, payload3, ctx3) {
2236
+ handleError_fn = /* @__PURE__ */ __name(async function(execution, error2, payload10, ctx10) {
2130
2237
  const retriesConfig = this._importedConfig?.retries ?? this._config.retries;
2131
2238
  const retry = this.task.retry ?? retriesConfig?.default;
2132
2239
  if (!retry) {
@@ -2141,13 +2248,13 @@ handleError_fn = /* @__PURE__ */ __name(async function(execution, error, payload
2141
2248
  };
2142
2249
  }
2143
2250
  return this._tracer.startActiveSpan("handleError()", async (span) => {
2144
- const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload3, error, {
2145
- ctx: ctx3,
2251
+ const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload10, error2, {
2252
+ ctx: ctx10,
2146
2253
  retry,
2147
2254
  retryDelayInMs: delay,
2148
2255
  retryAt: delay ? new Date(Date.now() + delay) : void 0
2149
- }) : this._importedConfig ? await this._handleErrorFn?.(payload3, error, {
2150
- ctx: ctx3,
2256
+ }) : this._importedConfig ? await this._handleErrorFn?.(payload10, error2, {
2257
+ ctx: ctx10,
2151
2258
  retry,
2152
2259
  retryDelayInMs: delay,
2153
2260
  retryAt: delay ? new Date(Date.now() + delay) : void 0