@trigger.dev/sdk 0.0.0-auto-yield-20231012092140 → 0.0.0-auto-yield-20231020151736
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.
- package/dist/index.d.ts +37 -27
- package/dist/index.js +66 -41
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ declare class ApiClient {
|
|
|
79
79
|
callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
80
80
|
idempotencyKey: z.ZodString;
|
|
81
81
|
attempts: z.ZodNumber;
|
|
82
|
+
forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
|
|
82
83
|
}, "strip", z.ZodTypeAny, {
|
|
83
84
|
id: string;
|
|
84
85
|
name: string;
|
|
@@ -111,6 +112,7 @@ declare class ApiClient {
|
|
|
111
112
|
} | null | undefined;
|
|
112
113
|
operation?: string | null | undefined;
|
|
113
114
|
callbackUrl?: string | null | undefined;
|
|
115
|
+
forceYield?: boolean | null | undefined;
|
|
114
116
|
}, {
|
|
115
117
|
id: string;
|
|
116
118
|
name: string;
|
|
@@ -143,6 +145,7 @@ declare class ApiClient {
|
|
|
143
145
|
} | null | undefined;
|
|
144
146
|
operation?: string | null | undefined;
|
|
145
147
|
callbackUrl?: string | null | undefined;
|
|
148
|
+
forceYield?: boolean | null | undefined;
|
|
146
149
|
}>;
|
|
147
150
|
cachedTasks: z.ZodOptional<z.ZodObject<{
|
|
148
151
|
tasks: z.ZodArray<z.ZodObject<{
|
|
@@ -222,6 +225,7 @@ declare class ApiClient {
|
|
|
222
225
|
} | null | undefined;
|
|
223
226
|
operation?: string | null | undefined;
|
|
224
227
|
callbackUrl?: string | null | undefined;
|
|
228
|
+
forceYield?: boolean | null | undefined;
|
|
225
229
|
};
|
|
226
230
|
cachedTasks?: {
|
|
227
231
|
tasks: {
|
|
@@ -267,6 +271,7 @@ declare class ApiClient {
|
|
|
267
271
|
} | null | undefined;
|
|
268
272
|
operation?: string | null | undefined;
|
|
269
273
|
callbackUrl?: string | null | undefined;
|
|
274
|
+
forceYield?: boolean | null | undefined;
|
|
270
275
|
};
|
|
271
276
|
cachedTasks?: {
|
|
272
277
|
tasks: {
|
|
@@ -334,6 +339,7 @@ declare class ApiClient {
|
|
|
334
339
|
callbackUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
335
340
|
idempotencyKey: z.ZodString;
|
|
336
341
|
attempts: z.ZodNumber;
|
|
342
|
+
forceYield: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
|
|
337
343
|
}, "strip", z.ZodTypeAny, {
|
|
338
344
|
id: string;
|
|
339
345
|
name: string;
|
|
@@ -366,6 +372,7 @@ declare class ApiClient {
|
|
|
366
372
|
} | null | undefined;
|
|
367
373
|
operation?: string | null | undefined;
|
|
368
374
|
callbackUrl?: string | null | undefined;
|
|
375
|
+
forceYield?: boolean | null | undefined;
|
|
369
376
|
}, {
|
|
370
377
|
id: string;
|
|
371
378
|
name: string;
|
|
@@ -398,6 +405,7 @@ declare class ApiClient {
|
|
|
398
405
|
} | null | undefined;
|
|
399
406
|
operation?: string | null | undefined;
|
|
400
407
|
callbackUrl?: string | null | undefined;
|
|
408
|
+
forceYield?: boolean | null | undefined;
|
|
401
409
|
}>>>;
|
|
402
410
|
completeTask(runId: string, id: string, task: CompleteTaskBodyInput): Promise<{
|
|
403
411
|
id: string;
|
|
@@ -431,6 +439,7 @@ declare class ApiClient {
|
|
|
431
439
|
} | null | undefined;
|
|
432
440
|
operation?: string | null | undefined;
|
|
433
441
|
callbackUrl?: string | null | undefined;
|
|
442
|
+
forceYield?: boolean | null | undefined;
|
|
434
443
|
}>;
|
|
435
444
|
failTask(runId: string, id: string, body: FailTaskBodyInput): Promise<{
|
|
436
445
|
id: string;
|
|
@@ -464,6 +473,7 @@ declare class ApiClient {
|
|
|
464
473
|
} | null | undefined;
|
|
465
474
|
operation?: string | null | undefined;
|
|
466
475
|
callbackUrl?: string | null | undefined;
|
|
476
|
+
forceYield?: boolean | null | undefined;
|
|
467
477
|
}>;
|
|
468
478
|
sendEvent(event: SendEvent, options?: SendEventOptions): Promise<{
|
|
469
479
|
id: string;
|
|
@@ -1402,12 +1412,12 @@ declare class IO {
|
|
|
1402
1412
|
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
1403
1413
|
get logger(): IOLogger;
|
|
1404
1414
|
/** `io.wait()` waits for the specified amount of time before continuing the Job. Delays work even if you're on a serverless platform with timeouts, or if your server goes down. They utilize [resumability](https://trigger.dev/docs/documentation/concepts/resumability) to ensure that the Run can be resumed after the delay.
|
|
1405
|
-
* @param
|
|
1415
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1406
1416
|
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
1407
1417
|
*/
|
|
1408
|
-
wait(
|
|
1418
|
+
wait(cacheKey: string | any[], seconds: number): Promise<void>;
|
|
1409
1419
|
/** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
|
|
1410
|
-
* @param
|
|
1420
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1411
1421
|
* @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
|
|
1412
1422
|
* @returns a TriggerStatus object that you can call `update()` on, to update the status.
|
|
1413
1423
|
* @example
|
|
@@ -1438,9 +1448,9 @@ declare class IO {
|
|
|
1438
1448
|
});
|
|
1439
1449
|
* ```
|
|
1440
1450
|
*/
|
|
1441
|
-
createStatus(
|
|
1451
|
+
createStatus(cacheKey: IntegrationTaskKey, initialStatus: InitialStatusUpdate): Promise<TriggerStatus>;
|
|
1442
1452
|
/** `io.backgroundFetch()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
|
|
1443
|
-
* @param
|
|
1453
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1444
1454
|
* @param url The URL to fetch from.
|
|
1445
1455
|
* @param requestInit The options for the request
|
|
1446
1456
|
* @param retry The options for retrying the request if it fails
|
|
@@ -1450,13 +1460,13 @@ declare class IO {
|
|
|
1450
1460
|
* - Ranges: 500-599
|
|
1451
1461
|
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
1452
1462
|
*/
|
|
1453
|
-
backgroundFetch<TResponseData>(
|
|
1463
|
+
backgroundFetch<TResponseData>(cacheKey: string | any[], url: string, requestInit?: FetchRequestInit, retry?: FetchRetryOptions): Promise<TResponseData>;
|
|
1454
1464
|
/** `io.sendEvent()` allows you to send an event from inside a Job run. The sent even will trigger any Jobs that are listening for that event (based on the name).
|
|
1455
|
-
* @param
|
|
1465
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1456
1466
|
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
1457
1467
|
* @param options Options for sending the event.
|
|
1458
1468
|
*/
|
|
1459
|
-
sendEvent(
|
|
1469
|
+
sendEvent(cacheKey: string | any[], event: SendEvent, options?: SendEventOptions): Promise<{
|
|
1460
1470
|
id: string;
|
|
1461
1471
|
name: string;
|
|
1462
1472
|
payload: ((string | number | boolean | {
|
|
@@ -1470,7 +1480,7 @@ declare class IO {
|
|
|
1470
1480
|
deliveredAt?: Date | null | undefined;
|
|
1471
1481
|
cancelledAt?: Date | null | undefined;
|
|
1472
1482
|
}>;
|
|
1473
|
-
getEvent(
|
|
1483
|
+
getEvent(cacheKey: string | any[], id: string): Promise<{
|
|
1474
1484
|
id: string;
|
|
1475
1485
|
name: string;
|
|
1476
1486
|
updatedAt: Date;
|
|
@@ -1483,11 +1493,11 @@ declare class IO {
|
|
|
1483
1493
|
createdAt: Date;
|
|
1484
1494
|
}>;
|
|
1485
1495
|
/** `io.cancelEvent()` allows you to cancel an event that was previously sent with `io.sendEvent()`. This will prevent any Jobs from running that are listening for that event if the event was sent with a delay
|
|
1486
|
-
* @param
|
|
1496
|
+
* @param cacheKey
|
|
1487
1497
|
* @param eventId
|
|
1488
1498
|
* @returns
|
|
1489
1499
|
*/
|
|
1490
|
-
cancelEvent(
|
|
1500
|
+
cancelEvent(cacheKey: string | any[], eventId: string): Promise<{
|
|
1491
1501
|
id: string;
|
|
1492
1502
|
name: string;
|
|
1493
1503
|
payload: ((string | number | boolean | {
|
|
@@ -1501,21 +1511,21 @@ declare class IO {
|
|
|
1501
1511
|
deliveredAt?: Date | null | undefined;
|
|
1502
1512
|
cancelledAt?: Date | null | undefined;
|
|
1503
1513
|
}>;
|
|
1504
|
-
updateSource(
|
|
1514
|
+
updateSource(cacheKey: string | any[], options: {
|
|
1505
1515
|
key: string;
|
|
1506
1516
|
} & UpdateTriggerSourceBodyV2): Promise<{
|
|
1507
1517
|
id: string;
|
|
1508
1518
|
key: string;
|
|
1509
1519
|
}>;
|
|
1510
1520
|
/** `io.registerInterval()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular interval.
|
|
1511
|
-
* @param
|
|
1521
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1512
1522
|
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1513
1523
|
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1514
1524
|
* @param options The options for the interval.
|
|
1515
1525
|
* @returns A promise that has information about the interval.
|
|
1516
1526
|
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1517
1527
|
*/
|
|
1518
|
-
registerInterval(
|
|
1528
|
+
registerInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: IntervalOptions): Promise<{
|
|
1519
1529
|
id: string;
|
|
1520
1530
|
schedule: {
|
|
1521
1531
|
options: {
|
|
@@ -1536,22 +1546,22 @@ declare class IO {
|
|
|
1536
1546
|
metadata?: any;
|
|
1537
1547
|
}>;
|
|
1538
1548
|
/** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
|
|
1539
|
-
* @param
|
|
1549
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1540
1550
|
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1541
1551
|
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1542
1552
|
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1543
1553
|
*/
|
|
1544
|
-
unregisterInterval(
|
|
1554
|
+
unregisterInterval(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
1545
1555
|
ok: boolean;
|
|
1546
1556
|
}>;
|
|
1547
1557
|
/** `io.registerCron()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular CRON schedule.
|
|
1548
|
-
* @param
|
|
1558
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1549
1559
|
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1550
1560
|
* @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
|
|
1551
1561
|
* @param options The options for the CRON schedule.
|
|
1552
1562
|
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1553
1563
|
*/
|
|
1554
|
-
registerCron(
|
|
1564
|
+
registerCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string, options: CronOptions): Promise<{
|
|
1555
1565
|
id: string;
|
|
1556
1566
|
schedule: {
|
|
1557
1567
|
options: {
|
|
@@ -1572,43 +1582,43 @@ declare class IO {
|
|
|
1572
1582
|
metadata?: any;
|
|
1573
1583
|
}>;
|
|
1574
1584
|
/** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
|
|
1575
|
-
* @param
|
|
1585
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1576
1586
|
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1577
1587
|
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1578
1588
|
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1579
1589
|
*/
|
|
1580
|
-
unregisterCron(
|
|
1590
|
+
unregisterCron(cacheKey: string | any[], dynamicSchedule: DynamicSchedule, id: string): Promise<{
|
|
1581
1591
|
ok: boolean;
|
|
1582
1592
|
}>;
|
|
1583
1593
|
/** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
|
|
1584
|
-
* @param
|
|
1594
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1585
1595
|
* @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
|
|
1586
1596
|
* @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
|
|
1587
1597
|
* @param params The params for the trigger.
|
|
1588
1598
|
* @deprecated Use `DynamicTrigger.register` instead.
|
|
1589
1599
|
*/
|
|
1590
|
-
registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(
|
|
1600
|
+
registerTrigger<TTrigger extends DynamicTrigger<EventSpecification<any>, ExternalSource<any, any, any>>>(cacheKey: string | any[], trigger: TTrigger, id: string, params: ExternalSourceParams<TTrigger["source"]>): Promise<{
|
|
1591
1601
|
id: string;
|
|
1592
1602
|
key: string;
|
|
1593
1603
|
} | undefined>;
|
|
1594
|
-
getAuth(
|
|
1604
|
+
getAuth(cacheKey: string | any[], clientId?: string): Promise<ConnectionAuth | undefined>;
|
|
1595
1605
|
/** `io.runTask()` allows you to run a [Task](https://trigger.dev/docs/documentation/concepts/tasks) from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. [Integrations](https://trigger.dev/docs/integrations) use Tasks internally to perform their actions.
|
|
1596
1606
|
*
|
|
1597
|
-
* @param
|
|
1607
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1598
1608
|
* @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
|
|
1599
1609
|
* @param options The options of how you'd like to run and log the Task.
|
|
1600
1610
|
* @param onError The callback that will be called when the Task fails. The callback receives the error, the Task and the IO as parameters. If you wish to retry then return an object with a `retryAt` property.
|
|
1601
1611
|
* @returns A Promise that resolves with the returned value of the callback.
|
|
1602
1612
|
*/
|
|
1603
|
-
runTask<T extends Json<T> | void>(
|
|
1613
|
+
runTask<T extends Json<T> | void>(cacheKey: string | any[], callback: (task: ServerTask, io: IO) => Promise<T>, options?: RunTaskOptions, onError?: RunTaskErrorCallback): Promise<T>;
|
|
1604
1614
|
/**
|
|
1605
1615
|
* `io.yield()` allows you to yield execution of the current run and resume it in a new function execution. Similar to `io.wait()` but does not create a task and resumes execution immediately.
|
|
1606
1616
|
*/
|
|
1607
|
-
yield(
|
|
1617
|
+
yield(cacheKey: string): void;
|
|
1608
1618
|
/**
|
|
1609
1619
|
* `io.brb()` is an alias of `io.yield()`
|
|
1610
1620
|
*/
|
|
1611
|
-
brb: (
|
|
1621
|
+
brb: (cacheKey: string) => void;
|
|
1612
1622
|
/** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](/sdk/io/runtask).
|
|
1613
1623
|
* A regular `try/catch` block on its own won't work as expected with Tasks. Internally `runTask()` throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
|
|
1614
1624
|
* @param tryCallback The code you wish to run
|
package/dist/index.js
CHANGED
|
@@ -478,19 +478,19 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
478
478
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
479
479
|
}
|
|
480
480
|
const jsonBody = await response.json();
|
|
481
|
-
const
|
|
482
|
-
if (!
|
|
481
|
+
const version2 = response.headers.get("trigger-version");
|
|
482
|
+
if (!version2) {
|
|
483
483
|
return {
|
|
484
484
|
version: "unversioned",
|
|
485
485
|
body: unversionedSchema.parse(jsonBody)
|
|
486
486
|
};
|
|
487
487
|
}
|
|
488
|
-
const versionedSchema = versionedSchemaMap[
|
|
488
|
+
const versionedSchema = versionedSchemaMap[version2];
|
|
489
489
|
if (!versionedSchema) {
|
|
490
|
-
throw new Error(`Unknown version ${
|
|
490
|
+
throw new Error(`Unknown version ${version2}`);
|
|
491
491
|
}
|
|
492
492
|
return {
|
|
493
|
-
version,
|
|
493
|
+
version: version2,
|
|
494
494
|
body: versionedSchema.parse(jsonBody)
|
|
495
495
|
};
|
|
496
496
|
}
|
|
@@ -619,11 +619,12 @@ var TriggerStatus = class {
|
|
|
619
619
|
__name(TriggerStatus, "TriggerStatus");
|
|
620
620
|
|
|
621
621
|
// src/io.ts
|
|
622
|
-
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
622
|
+
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
623
623
|
var IO = class {
|
|
624
624
|
constructor(options) {
|
|
625
625
|
__privateAdd(this, _addToCachedTasks);
|
|
626
626
|
__privateAdd(this, _detectAutoYield);
|
|
627
|
+
__privateAdd(this, _forceYield);
|
|
627
628
|
__privateAdd(this, _getTimeElapsed);
|
|
628
629
|
__privateAdd(this, _getRemainingTimeInMillis);
|
|
629
630
|
__publicField(this, "brb", this.yield.bind(this));
|
|
@@ -724,8 +725,8 @@ var IO = class {
|
|
|
724
725
|
}
|
|
725
726
|
});
|
|
726
727
|
}
|
|
727
|
-
async wait(
|
|
728
|
-
return await this.runTask(
|
|
728
|
+
async wait(cacheKey, seconds) {
|
|
729
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
729
730
|
}, {
|
|
730
731
|
name: "wait",
|
|
731
732
|
icon: "clock",
|
|
@@ -739,15 +740,15 @@ var IO = class {
|
|
|
739
740
|
}
|
|
740
741
|
});
|
|
741
742
|
}
|
|
742
|
-
async createStatus(
|
|
743
|
-
const id = typeof
|
|
743
|
+
async createStatus(cacheKey, initialStatus) {
|
|
744
|
+
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
744
745
|
const status = new TriggerStatus(id, this);
|
|
745
|
-
await status.update(
|
|
746
|
+
await status.update(cacheKey, initialStatus);
|
|
746
747
|
return status;
|
|
747
748
|
}
|
|
748
|
-
async backgroundFetch(
|
|
749
|
+
async backgroundFetch(cacheKey, url, requestInit, retry2) {
|
|
749
750
|
const urlObject = new URL(url);
|
|
750
|
-
return await this.runTask(
|
|
751
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
751
752
|
return task.output;
|
|
752
753
|
}, {
|
|
753
754
|
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
@@ -776,8 +777,8 @@ var IO = class {
|
|
|
776
777
|
]
|
|
777
778
|
});
|
|
778
779
|
}
|
|
779
|
-
async sendEvent(
|
|
780
|
-
return await this.runTask(
|
|
780
|
+
async sendEvent(cacheKey, event, options) {
|
|
781
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
781
782
|
return await this._triggerClient.sendEvent(event, options);
|
|
782
783
|
}, {
|
|
783
784
|
name: "sendEvent",
|
|
@@ -799,8 +800,8 @@ var IO = class {
|
|
|
799
800
|
]
|
|
800
801
|
});
|
|
801
802
|
}
|
|
802
|
-
async getEvent(
|
|
803
|
-
return await this.runTask(
|
|
803
|
+
async getEvent(cacheKey, id) {
|
|
804
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
804
805
|
return await this._triggerClient.getEvent(id);
|
|
805
806
|
}, {
|
|
806
807
|
name: "getEvent",
|
|
@@ -815,8 +816,8 @@ var IO = class {
|
|
|
815
816
|
]
|
|
816
817
|
});
|
|
817
818
|
}
|
|
818
|
-
async cancelEvent(
|
|
819
|
-
return await this.runTask(
|
|
819
|
+
async cancelEvent(cacheKey, eventId) {
|
|
820
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
820
821
|
return await this._triggerClient.cancelEvent(eventId);
|
|
821
822
|
}, {
|
|
822
823
|
name: "cancelEvent",
|
|
@@ -831,8 +832,8 @@ var IO = class {
|
|
|
831
832
|
]
|
|
832
833
|
});
|
|
833
834
|
}
|
|
834
|
-
async updateSource(
|
|
835
|
-
return this.runTask(
|
|
835
|
+
async updateSource(cacheKey, options) {
|
|
836
|
+
return this.runTask(cacheKey, async (task) => {
|
|
836
837
|
return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
|
|
837
838
|
}, {
|
|
838
839
|
name: "Update Source",
|
|
@@ -851,8 +852,8 @@ var IO = class {
|
|
|
851
852
|
}
|
|
852
853
|
});
|
|
853
854
|
}
|
|
854
|
-
async registerInterval(
|
|
855
|
-
return await this.runTask(
|
|
855
|
+
async registerInterval(cacheKey, dynamicSchedule, id, options) {
|
|
856
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
856
857
|
return dynamicSchedule.register(id, {
|
|
857
858
|
type: "interval",
|
|
858
859
|
options
|
|
@@ -876,8 +877,8 @@ var IO = class {
|
|
|
876
877
|
params: options
|
|
877
878
|
});
|
|
878
879
|
}
|
|
879
|
-
async unregisterInterval(
|
|
880
|
-
return await this.runTask(
|
|
880
|
+
async unregisterInterval(cacheKey, dynamicSchedule, id) {
|
|
881
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
881
882
|
return dynamicSchedule.unregister(id);
|
|
882
883
|
}, {
|
|
883
884
|
name: "unregister-interval",
|
|
@@ -893,8 +894,8 @@ var IO = class {
|
|
|
893
894
|
]
|
|
894
895
|
});
|
|
895
896
|
}
|
|
896
|
-
async registerCron(
|
|
897
|
-
return await this.runTask(
|
|
897
|
+
async registerCron(cacheKey, dynamicSchedule, id, options) {
|
|
898
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
898
899
|
return dynamicSchedule.register(id, {
|
|
899
900
|
type: "cron",
|
|
900
901
|
options
|
|
@@ -918,8 +919,8 @@ var IO = class {
|
|
|
918
919
|
params: options
|
|
919
920
|
});
|
|
920
921
|
}
|
|
921
|
-
async unregisterCron(
|
|
922
|
-
return await this.runTask(
|
|
922
|
+
async unregisterCron(cacheKey, dynamicSchedule, id) {
|
|
923
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
923
924
|
return dynamicSchedule.unregister(id);
|
|
924
925
|
}, {
|
|
925
926
|
name: "unregister-cron",
|
|
@@ -935,8 +936,8 @@ var IO = class {
|
|
|
935
936
|
]
|
|
936
937
|
});
|
|
937
938
|
}
|
|
938
|
-
async registerTrigger(
|
|
939
|
-
return await this.runTask(
|
|
939
|
+
async registerTrigger(cacheKey, trigger, id, params) {
|
|
940
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
940
941
|
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
941
942
|
return trigger.register(id, params);
|
|
942
943
|
}, {
|
|
@@ -961,30 +962,30 @@ var IO = class {
|
|
|
961
962
|
params
|
|
962
963
|
});
|
|
963
964
|
}
|
|
964
|
-
async getAuth(
|
|
965
|
+
async getAuth(cacheKey, clientId) {
|
|
965
966
|
if (!clientId) {
|
|
966
967
|
return;
|
|
967
968
|
}
|
|
968
|
-
return this.runTask(
|
|
969
|
+
return this.runTask(cacheKey, async (task) => {
|
|
969
970
|
return await this._triggerClient.getAuth(clientId);
|
|
970
971
|
}, {
|
|
971
972
|
name: "get-auth"
|
|
972
973
|
});
|
|
973
974
|
}
|
|
974
|
-
async runTask(
|
|
975
|
+
async runTask(cacheKey, callback, options, onError) {
|
|
975
976
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
976
977
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
977
978
|
if (parentId) {
|
|
978
979
|
this._logger.debug("Using parent task", {
|
|
979
980
|
parentId,
|
|
980
|
-
|
|
981
|
+
cacheKey,
|
|
981
982
|
options
|
|
982
983
|
});
|
|
983
984
|
}
|
|
984
985
|
const idempotencyKey = await generateIdempotencyKey([
|
|
985
986
|
this._id,
|
|
986
987
|
parentId ?? "",
|
|
987
|
-
|
|
988
|
+
cacheKey
|
|
988
989
|
].flat());
|
|
989
990
|
const cachedTask = this._cachedTasks.get(idempotencyKey);
|
|
990
991
|
if (cachedTask && cachedTask.status === "COMPLETED") {
|
|
@@ -1005,7 +1006,7 @@ var IO = class {
|
|
|
1005
1006
|
}
|
|
1006
1007
|
const response = await this._apiClient.runTask(this._id, {
|
|
1007
1008
|
idempotencyKey,
|
|
1008
|
-
displayKey: typeof
|
|
1009
|
+
displayKey: typeof cacheKey === "string" ? cacheKey : void 0,
|
|
1009
1010
|
noop: false,
|
|
1010
1011
|
...options ?? {},
|
|
1011
1012
|
parentId
|
|
@@ -1013,6 +1014,12 @@ var IO = class {
|
|
|
1013
1014
|
cachedTasksCursor: this._cachedTasksCursor
|
|
1014
1015
|
});
|
|
1015
1016
|
const task = response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1017
|
+
if (task.forceYield) {
|
|
1018
|
+
this._logger.debug("Forcing yield after run task", {
|
|
1019
|
+
idempotencyKey
|
|
1020
|
+
});
|
|
1021
|
+
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1022
|
+
}
|
|
1016
1023
|
if (response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1017
1024
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1018
1025
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
@@ -1075,6 +1082,12 @@ var IO = class {
|
|
|
1075
1082
|
output: output ?? void 0,
|
|
1076
1083
|
properties: task.outputProperties ?? void 0
|
|
1077
1084
|
});
|
|
1085
|
+
if (completedTask.forceYield) {
|
|
1086
|
+
this._logger.debug("Forcing yield after task completed", {
|
|
1087
|
+
idempotencyKey
|
|
1088
|
+
});
|
|
1089
|
+
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_complete_task");
|
|
1090
|
+
}
|
|
1078
1091
|
this._stats.executedTasks++;
|
|
1079
1092
|
if (completedTask.status === "CANCELED") {
|
|
1080
1093
|
throw new CanceledWithTaskError(completedTask);
|
|
@@ -1156,15 +1169,15 @@ var IO = class {
|
|
|
1156
1169
|
taskId: task.id
|
|
1157
1170
|
}, executeTask);
|
|
1158
1171
|
}
|
|
1159
|
-
yield(
|
|
1172
|
+
yield(cacheKey) {
|
|
1160
1173
|
if (!(0, import_core3.supportsFeature)("yieldExecution", this._serverVersion)) {
|
|
1161
1174
|
console.warn("[trigger.dev] io.yield() is not support by the version of the Trigger.dev server you are using, you will need to upgrade your self-hosted Trigger.dev instance.");
|
|
1162
1175
|
return;
|
|
1163
1176
|
}
|
|
1164
|
-
if (this._yieldedExecutions.includes(
|
|
1177
|
+
if (this._yieldedExecutions.includes(cacheKey)) {
|
|
1165
1178
|
return;
|
|
1166
1179
|
}
|
|
1167
|
-
throw new YieldExecutionError(
|
|
1180
|
+
throw new YieldExecutionError(cacheKey);
|
|
1168
1181
|
}
|
|
1169
1182
|
async try(tryCallback, catchCallback) {
|
|
1170
1183
|
try {
|
|
@@ -1197,6 +1210,13 @@ detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500,
|
|
|
1197
1210
|
}
|
|
1198
1211
|
}
|
|
1199
1212
|
}, "#detectAutoYield");
|
|
1213
|
+
_forceYield = new WeakSet();
|
|
1214
|
+
forceYield_fn = /* @__PURE__ */ __name(function(location1) {
|
|
1215
|
+
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1216
|
+
if (timeRemaining) {
|
|
1217
|
+
throw new AutoYieldExecutionError(location1, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1218
|
+
}
|
|
1219
|
+
}, "#forceYield");
|
|
1200
1220
|
_getTimeElapsed = new WeakSet();
|
|
1201
1221
|
getTimeElapsed_fn = /* @__PURE__ */ __name(function() {
|
|
1202
1222
|
return performance.now() - this._timeOrigin;
|
|
@@ -1658,6 +1678,9 @@ var DynamicSchedule = class {
|
|
|
1658
1678
|
};
|
|
1659
1679
|
__name(DynamicSchedule, "DynamicSchedule");
|
|
1660
1680
|
|
|
1681
|
+
// package.json
|
|
1682
|
+
var version = "0.0.0-auto-yield-20231020151736";
|
|
1683
|
+
|
|
1661
1684
|
// src/triggerClient.ts
|
|
1662
1685
|
var registerSourceEvent = {
|
|
1663
1686
|
name: import_core7.REGISTER_SOURCE_EVENT_V2,
|
|
@@ -1958,7 +1981,8 @@ var TriggerClient = class {
|
|
|
1958
1981
|
};
|
|
1959
1982
|
}
|
|
1960
1983
|
case "PROBE_EXECUTION_TIMEOUT": {
|
|
1961
|
-
const
|
|
1984
|
+
const json = await request.json();
|
|
1985
|
+
const timeout = json?.timeout ?? 15 * 60 * 1e3;
|
|
1962
1986
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1963
1987
|
return {
|
|
1964
1988
|
status: 200,
|
|
@@ -2586,6 +2610,7 @@ _standardResponseHeaders = new WeakSet();
|
|
|
2586
2610
|
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
2587
2611
|
return {
|
|
2588
2612
|
"Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
2613
|
+
"Trigger-SDK-Version": version,
|
|
2589
2614
|
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
2590
2615
|
};
|
|
2591
2616
|
}, "#standardResponseHeaders");
|