1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | exports.taskQueue = exports.TaskQueueBuilder = void 0;
|
25 | const encoding_1 = require("../../common/encoding");
|
26 | const tasks_1 = require("../../common/providers/tasks");
|
27 | const manifest_1 = require("../../runtime/manifest");
|
28 | const cloud_functions_1 = require("../cloud-functions");
|
29 |
|
30 |
|
31 |
|
32 | class TaskQueueBuilder {
|
33 |
|
34 | constructor(tqOpts, depOpts) {
|
35 | this.tqOpts = tqOpts;
|
36 | this.depOpts = depOpts;
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | onDispatch(handler) {
|
44 | var _a, _b;
|
45 |
|
46 |
|
47 |
|
48 | const fixedLen = (data, context) => handler(data, context);
|
49 | const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
50 | func.__trigger = {
|
51 | ...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
52 | taskQueueTrigger: {},
|
53 | };
|
54 | (0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "retryConfig");
|
55 | (0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "rateLimits");
|
56 | (0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "invoker", "invoker", encoding_1.convertInvoker);
|
57 | func.__endpoint = {
|
58 | platform: "gcfv1",
|
59 | ...(0, manifest_1.initV1Endpoint)(this.depOpts),
|
60 | ...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
|
61 | taskQueueTrigger: (0, manifest_1.initTaskQueueTrigger)(this.depOpts),
|
62 | };
|
63 | (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.retryConfig, ((_a = this.tqOpts) === null || _a === void 0 ? void 0 : _a.retryConfig) || {}, "maxAttempts", "maxBackoffSeconds", "maxDoublings", "maxRetrySeconds", "minBackoffSeconds");
|
64 | (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.rateLimits, ((_b = this.tqOpts) === null || _b === void 0 ? void 0 : _b.rateLimits) || {}, "maxConcurrentDispatches", "maxDispatchesPerSecond");
|
65 | (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, "invoker", "invoker", encoding_1.convertInvoker);
|
66 | func.__requiredAPIs = [
|
67 | {
|
68 | api: "cloudtasks.googleapis.com",
|
69 | reason: "Needed for task queue functions",
|
70 | },
|
71 | ];
|
72 | func.run = handler;
|
73 | return func;
|
74 | }
|
75 | }
|
76 | exports.TaskQueueBuilder = TaskQueueBuilder;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function taskQueue(options) {
|
83 | return new TaskQueueBuilder(options);
|
84 | }
|
85 | exports.taskQueue = taskQueue;
|