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.onTaskDispatched = void 0;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const encoding_1 = require("../../common/encoding");
|
30 | const tasks_1 = require("../../common/providers/tasks");
|
31 | const options = require("../options");
|
32 | const trace_1 = require("../trace");
|
33 | const manifest_1 = require("../../runtime/manifest");
|
34 | const onInit_1 = require("../../common/onInit");
|
35 | function onTaskDispatched(optsOrHandler, handler) {
|
36 | let opts;
|
37 | if (arguments.length === 1) {
|
38 | opts = {};
|
39 | handler = optsOrHandler;
|
40 | }
|
41 | else {
|
42 | opts = optsOrHandler;
|
43 | }
|
44 |
|
45 |
|
46 | const fixedLen = (req) => handler(req);
|
47 | const func = (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)((0, tasks_1.onDispatchHandler)(fixedLen)));
|
48 | Object.defineProperty(func, "__trigger", {
|
49 | get: () => {
|
50 | const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
51 |
|
52 |
|
53 | const specificOpts = options.optionsToTriggerAnnotations(opts);
|
54 | const taskQueueTrigger = {};
|
55 | (0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, "retryConfig", "rateLimits");
|
56 | (0, encoding_1.convertIfPresent)(taskQueueTrigger, options.getGlobalOptions(), "invoker", "invoker", encoding_1.convertInvoker);
|
57 | (0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, "invoker", "invoker", encoding_1.convertInvoker);
|
58 | return {
|
59 | platform: "gcfv2",
|
60 | ...baseOpts,
|
61 | ...specificOpts,
|
62 | labels: {
|
63 | ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
64 | ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
65 | },
|
66 | taskQueueTrigger,
|
67 | };
|
68 | },
|
69 | });
|
70 | const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
71 |
|
72 |
|
73 | const specificOpts = options.optionsToEndpoint(opts);
|
74 | func.__endpoint = {
|
75 | platform: "gcfv2",
|
76 | ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
|
77 | ...baseOpts,
|
78 | ...specificOpts,
|
79 | labels: {
|
80 | ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
81 | ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
82 | },
|
83 | taskQueueTrigger: (0, manifest_1.initTaskQueueTrigger)(options.getGlobalOptions(), opts),
|
84 | };
|
85 | (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.retryConfig, opts.retryConfig, "maxAttempts", "maxBackoffSeconds", "maxDoublings", "maxRetrySeconds", "minBackoffSeconds");
|
86 | (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.rateLimits, opts.rateLimits, "maxConcurrentDispatches", "maxDispatchesPerSecond");
|
87 | (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, options.getGlobalOptions(), "invoker", "invoker", encoding_1.convertInvoker);
|
88 | (0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, opts, "invoker", "invoker", encoding_1.convertInvoker);
|
89 | (0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, "retry", "retry");
|
90 | func.__requiredAPIs = [
|
91 | {
|
92 | api: "cloudtasks.googleapis.com",
|
93 | reason: "Needed for task queue functions",
|
94 | },
|
95 | ];
|
96 | func.run = handler;
|
97 | return func;
|
98 | }
|
99 | exports.onTaskDispatched = onTaskDispatched;
|