1 | import { ResetValue } from "../../common/options";
|
2 | import { AuthData, RateLimits, Request, RetryConfig } from "../../common/providers/tasks";
|
3 | import * as options from "../options";
|
4 | import { HttpsFunction } from "./https";
|
5 | import { Expression } from "../../params";
|
6 | import { SecretParam } from "../../params/types";
|
7 | export { AuthData, Request, RateLimits, RetryConfig };
|
8 | export interface TaskQueueOptions extends options.EventHandlerOptions {
|
9 | /** How a task should be retried in the event of a non-2xx return. */
|
10 | retryConfig?: RetryConfig;
|
11 | /** How congestion control should be applied to the function. */
|
12 | rateLimits?: RateLimits;
|
13 | /**
|
14 | * Who can enqueue tasks for this function.
|
15 | *
|
16 | * @remakrs
|
17 | * If left unspecified, only service accounts which have
|
18 | * `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
|
19 | * will have permissions.
|
20 | */
|
21 | invoker?: "private" | string | string[];
|
22 | /**
|
23 | * If true, do not deploy or emulate this function.
|
24 | */
|
25 | omit?: boolean | Expression<boolean>;
|
26 | /**
|
27 | * Region where functions should be deployed.
|
28 | */
|
29 | region?: options.SupportedRegion | string | Expression<string> | ResetValue;
|
30 | /**
|
31 | * Amount of memory to allocate to a function.
|
32 | */
|
33 | memory?: options.MemoryOption | Expression<number> | ResetValue;
|
34 | /**
|
35 | * Timeout for the function in seconds, possible values are 0 to 540.
|
36 | * HTTPS functions can specify a higher timeout.
|
37 | *
|
38 | * @remarks
|
39 | * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
40 | * function depends on the type of function: Event handling functions have a
|
41 | * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
42 | * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
43 | * timeout of 1,800s (30 minutes)
|
44 | */
|
45 | timeoutSeconds?: number | Expression<number> | ResetValue;
|
46 | /**
|
47 | * Min number of actual instances to be running at a given time.
|
48 | *
|
49 | * @remarks
|
50 | * Instances will be billed for memory allocation and 10% of CPU allocation
|
51 | * while idle.
|
52 | */
|
53 | minInstances?: number | Expression<number> | ResetValue;
|
54 | /**
|
55 | * Max number of instances to be running in parallel.
|
56 | */
|
57 | maxInstances?: number | Expression<number> | ResetValue;
|
58 | /**
|
59 | * Number of requests a function can serve at once.
|
60 | *
|
61 | * @remarks
|
62 | * Can only be applied to functions running on Cloud Functions v2.
|
63 | * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
64 | * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
65 | * The maximum value for concurrency is 1,000.
|
66 | */
|
67 | concurrency?: number | Expression<number> | ResetValue;
|
68 | /**
|
69 | * Fractional number of CPUs to allocate to a function.
|
70 | *
|
71 | * @remarks
|
72 | * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
73 | * This is different from the defaults when using the gcloud utility and is different from
|
74 | * the fixed amount assigned in Google Cloud Functions generation 1.
|
75 | * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
76 | * to the value "gcf_gen1"
|
77 | */
|
78 | cpu?: number | "gcf_gen1";
|
79 | /**
|
80 | * Connect cloud function to specified VPC connector.
|
81 | */
|
82 | vpcConnector?: string | Expression<string> | ResetValue;
|
83 | /**
|
84 | * Egress settings for VPC connector.
|
85 | */
|
86 | vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
|
87 | /**
|
88 | * Specific service account for the function to run as.
|
89 | */
|
90 | serviceAccount?: string | Expression<string> | ResetValue;
|
91 | /**
|
92 | * Ingress settings which control where this function can be called from.
|
93 | */
|
94 | ingressSettings?: options.IngressSetting | ResetValue;
|
95 | /**
|
96 | * User labels to set on the function.
|
97 | */
|
98 | labels?: Record<string, string>;
|
99 | secrets?: (string | SecretParam)[];
|
100 | /** Whether failed executions should be delivered again. */
|
101 | retry?: boolean;
|
102 | }
|
103 | /**
|
104 | * A handler for tasks.
|
105 | * @typeParam T - The task data interface. Task data is unmarshaled from JSON.
|
106 | */
|
107 | export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
108 | /**
|
109 | * The callback passed to the `TaskQueueFunction` constructor.
|
110 | * @param request - A TaskRequest containing data and auth information.
|
111 | * @returns Any return value. Google Cloud Functions will await any promise
|
112 | * before shutting down your function. Resolved return values
|
113 | * are only used for unit testing purposes.
|
114 | */
|
115 | run(request: Request<T>): void | Promise<void>;
|
116 | }
|
117 | /**
|
118 | * Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
119 | * @param handler - A callback to handle task requests.
|
120 | * @typeParam Args - The interface for the request's `data` field.
|
121 | * @returns A function you can export and deploy.
|
122 | */
|
123 | export declare function onTaskDispatched<Args = any>(handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
124 | /**
|
125 | * Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
126 | * @param options - Configuration for the task queue or Cloud Function.
|
127 | * @param handler - A callback to handle task requests.
|
128 | * @typeParam Args - The interface for the request's `data` field.
|
129 | * @returns A function you can export and deploy.
|
130 | */
|
131 | export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|