MCPcopy
hub / github.com/triggerdotdev/trigger.dev / executeTask

Method executeTask

packages/trigger-sdk/src/io.ts:1251–1374  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1249 this.#detectAutoYield("before_execute_task", 1500);
1250
1251 const executeTask = async () => {
1252 try {
1253 const result = await callback(task, this);
1254
1255 if (task.status === "WAITING" && task.callbackUrl) {
1256 this._logger.debug("Waiting for remote callback", {
1257 idempotencyKey,
1258 task,
1259 });
1260 return {} as T;
1261 }
1262
1263 const output = this._outputSerializer.serialize(result);
1264
1265 this._logger.debug("Completing using output", {
1266 idempotencyKey,
1267 task,
1268 });
1269
1270 this.#detectAutoYield("before_complete_task", 500, task, output);
1271
1272 const completedTask = await this.#doCompleteTask(task.id, {
1273 output,
1274 properties: task.outputProperties ?? undefined,
1275 });
1276
1277 if (!completedTask) {
1278 this.#forceYield("before_complete_task", task, output);
1279 throw new Error("Failed to complete task"); // this shouldn't actually happen, because forceYield will throw
1280 }
1281
1282 if (completedTask.forceYield) {
1283 this._logger.debug("Forcing yield after task completed", {
1284 idempotencyKey,
1285 });
1286
1287 this.#forceYield("after_complete_task");
1288 }
1289
1290 this._stats.executedTasks++;
1291
1292 if (completedTask.status === "CANCELED") {
1293 throw new CanceledWithTaskError(completedTask);
1294 }
1295
1296 this.#detectAutoYield("after_complete_task", 500);
1297
1298 const deserializedOutput = this._outputSerializer.deserialize<T>(output);
1299
1300 return options?.parseOutput ? options.parseOutput(deserializedOutput) : deserializedOutput;
1301 } catch (error) {
1302 if (isTriggerError(error)) {
1303 throw error;
1304 }
1305
1306 let skipRetrying = false;
1307
1308 if (onError) {

Callers

nothing calls this directly

Calls 10

#detectAutoYieldMethod · 0.95
#doCompleteTaskMethod · 0.95
#forceYieldMethod · 0.95
isTriggerErrorFunction · 0.90
calculateRetryAtFunction · 0.90
failTaskMethod · 0.80
debugMethod · 0.65
serializeMethod · 0.65
deserializeMethod · 0.65
onErrorFunction · 0.50

Tested by

no test coverage detected