MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / createTask

Function createTask

packages/trigger-sdk/src/v3/shared.ts:332–696  ·  view source on GitHub ↗
(
  params: TaskOptions<TInput, TOutput, TInitOutput>
)

Source from the content-addressed store, hash-verified

330};
331
332export function createTask<TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(
333 params: TaskOptions<TInput, TOutput, TInitOutput>
334): Task<TInput, TOutput> {
335 const task: Task<TInput, TOutput> = {
336 id: params.id,
337 trigger: async (payload, options) => {
338 const apiClient = apiClientManager.client;
339
340 if (!apiClient) {
341 throw apiClientMissingError();
342 }
343
344 const taskMetadata = taskCatalog.getTaskMetadata(params.id);
345
346 const payloadPacket = await stringifyIO(payload);
347
348 const handle = await tracer.startActiveSpan(
349 taskMetadata ? "Trigger" : `${params.id} trigger()`,
350 async (span) => {
351 const response = await apiClient.triggerTask(
352 params.id,
353 {
354 payload: payloadPacket.data,
355 options: {
356 queue: options?.queue ?? params.queue,
357 concurrencyKey: options?.concurrencyKey,
358 test: taskContext.ctx?.run.isTest,
359 payloadType: payloadPacket.dataType,
360 idempotencyKey: options?.idempotencyKey,
361 },
362 },
363 { spanParentAsLink: true }
364 );
365
366 span.setAttribute("messaging.message.id", response.id);
367
368 return response;
369 },
370 {
371 kind: SpanKind.PRODUCER,
372 attributes: {
373 [SEMATTRS_MESSAGING_OPERATION]: "publish",
374 [SemanticInternalAttributes.STYLE_ICON]: "trigger",
375 ["messaging.client_id"]: taskContext.worker?.id,
376 [SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
377 [SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
378 ...(taskMetadata
379 ? accessoryAttributes({
380 items: [
381 {
382 text: `${taskMetadata.exportName}.trigger()`,
383 variant: "normal",
384 },
385 ],
386 style: "codepath",
387 })
388 : {}),
389 },

Callers 2

taskFunction · 0.90
taskFunction · 0.90

Calls 15

stringifyIOFunction · 0.90
accessoryAttributesFunction · 0.90
apiClientMissingErrorFunction · 0.85
getBatchResultsFunction · 0.85
startActiveSpanMethod · 0.80
triggerTaskMethod · 0.80
batchTriggerTaskMethod · 0.80
getRunResultMethod · 0.80
findMethod · 0.80
getTaskMetadataMethod · 0.65
logMethod · 0.65
waitForTaskMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…