1 | import { DecodedIdToken } from "firebase-admin/auth";
|
2 | import { Expression } from "../../params";
|
3 | import { ResetValue } from "../options";
|
4 | /** How a task should be retried in the event of a non-2xx return. */
|
5 | export interface RetryConfig {
|
6 | /**
|
7 | * Maximum number of times a request should be attempted.
|
8 | * If left unspecified, will default to 3.
|
9 | */
|
10 | maxAttempts?: number | Expression<number> | ResetValue;
|
11 | /**
|
12 | * Maximum amount of time for retrying failed task.
|
13 | * If left unspecified will retry indefinitely.
|
14 | */
|
15 | maxRetrySeconds?: number | Expression<number> | ResetValue;
|
16 | /**
|
17 | * The maximum amount of time to wait between attempts.
|
18 | * If left unspecified will default to 1hr.
|
19 | */
|
20 | maxBackoffSeconds?: number | Expression<number> | ResetValue;
|
21 | /**
|
22 | * The maximum number of times to double the backoff between
|
23 | * retries. If left unspecified will default to 16.
|
24 | */
|
25 | maxDoublings?: number | Expression<number> | ResetValue;
|
26 | /**
|
27 | * The minimum time to wait between attempts. If left unspecified
|
28 | * will default to 100ms.
|
29 | */
|
30 | minBackoffSeconds?: number | Expression<number> | ResetValue;
|
31 | }
|
32 | /** How congestion control should be applied to the function. */
|
33 | export interface RateLimits {
|
34 | /**
|
35 | * The maximum number of requests that can be processed at a time.
|
36 | * If left unspecified, will default to 1000.
|
37 | */
|
38 | maxConcurrentDispatches?: number | Expression<number> | ResetValue;
|
39 | /**
|
40 | * The maximum number of requests that can be invoked per second.
|
41 | * If left unspecified, will default to 500.
|
42 | */
|
43 | maxDispatchesPerSecond?: number | Expression<number> | ResetValue;
|
44 | }
|
45 | /** Metadata about the authorization used to invoke a function. */
|
46 | export interface AuthData {
|
47 | uid: string;
|
48 | token: DecodedIdToken;
|
49 | }
|
50 | /** Metadata about a call to a Task Queue function. */
|
51 | export interface TaskContext {
|
52 | /**
|
53 | * The result of decoding and verifying an ODIC token.
|
54 | */
|
55 | auth?: AuthData;
|
56 | /**
|
57 | * The name of the queue.
|
58 | * Populated via the `X-CloudTasks-QueueName` header.
|
59 | */
|
60 | queueName: string;
|
61 | /**
|
62 | * The "short" name of the task, or, if no name was specified at creation, a unique
|
63 | * system-generated id.
|
64 | * This is the "my-task-id" value in the complete task name, such as "task_name =
|
65 | * projects/my-project-id/locations/my-location/queues/my-queue-id/tasks/my-task-id."
|
66 | * Populated via the `X-CloudTasks-TaskName` header.
|
67 | */
|
68 | id: string;
|
69 | /**
|
70 | * The number of times this task has been retried.
|
71 | * For the first attempt, this value is 0. This number includes attempts where the task failed
|
72 | * due to 5XX error codes and never reached the execution phase.
|
73 | * Populated via the `X-CloudTasks-TaskRetryCount` header.
|
74 | */
|
75 | retryCount: number;
|
76 | /**
|
77 | * The total number of times that the task has received a response from the handler.
|
78 | * Since Cloud Tasks deletes the task once a successful response has been received, all
|
79 | * previous handler responses were failures. This number does not include failures due to 5XX
|
80 | * error codes.
|
81 | * Populated via the `X-CloudTasks-TaskExecutionCount` header.
|
82 | */
|
83 | executionCount: number;
|
84 | /**
|
85 | * The schedule time of the task, as an RFC 3339 string in UTC time zone.
|
86 | * Populated via the `X-CloudTasks-TaskETA` header, which uses seconds since January 1 1970.
|
87 | */
|
88 | scheduledTime: string;
|
89 | /**
|
90 | * The HTTP response code from the previous retry.
|
91 | * Populated via the `X-CloudTasks-TaskPreviousResponse` header
|
92 | */
|
93 | previousResponse?: number;
|
94 | /**
|
95 | * The reason for retrying the task.
|
96 | * Populated via the `X-CloudTasks-TaskRetryReason` header.
|
97 | */
|
98 | retryReason?: string;
|
99 | /**
|
100 | * Raw request headers.
|
101 | */
|
102 | headers?: Record<string, string>;
|
103 | }
|
104 | /**
|
105 | * The request used to call a task queue function.
|
106 | */
|
107 | export type Request<T = any> = TaskContext & {
|
108 | /**
|
109 | * The parameters used by a client when calling this function.
|
110 | */
|
111 | data: T;
|
112 | };
|