Skip to content

Commit 1c35efa

Browse files
authored
Improve documentation for task queue functions (#1112)
* Improve documentation for task queue functions * PR feedback
1 parent 4ab383b commit 1c35efa

File tree

3 files changed

+68
-22
lines changed

3 files changed

+68
-22
lines changed

src/common/providers/tasks.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ export interface RetryConfig {
6161

6262
/** How congestion control should be applied to the function. */
6363
export interface RateLimits {
64-
// If left unspecified, wild default to 1000
64+
/**
65+
* The maximum number of requests that can be outstanding at a time.
66+
* If left unspecified, will default to 1000.
67+
*/
6568
maxConcurrentDispatches?: number;
6669

67-
// If left unspecified, will default to 500
70+
/**
71+
* The maximum number of requests that can be invoked per second.
72+
* If left unspecified, will default to 500.
73+
*/
6874
maxDispatchesPerSecond?: number;
6975
}
7076

77+
/** Metadata about the authorization used to invoke a function. */
7178
export interface AuthData {
7279
uid: string;
7380
token: firebase.auth.DecodedIdToken;

src/providers/tasks.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,51 +38,67 @@ import {
3838
import { DeploymentOptions } from '../function-configuration';
3939
import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
4040

41-
export {
42-
/** @hidden */
43-
RetryConfig as RetryPolicy,
44-
/** @hidden */
45-
RateLimits,
46-
/** @hidden */
47-
TaskContext,
48-
};
41+
export { RetryConfig, RateLimits, TaskContext };
4942

5043
/**
51-
* Configurations for Task Queue Functions.
52-
* @hidden
44+
* Options for configuring the task queue to listen to.
5345
*/
5446
export interface TaskQueueOptions {
47+
/** How a task should be retried in the event of a non-2xx return. */
5548
retryConfig?: RetryConfig;
49+
/** How congestion control should be applied to the function. */
5650
rateLimits?: RateLimits;
5751

5852
/**
5953
* Who can enqueue tasks for this function.
6054
* If left unspecified, only service accounts which have
61-
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
55+
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
6256
* will have permissions.
6357
*/
6458
invoker?: 'private' | string | string[];
6559
}
6660

67-
/** @hidden */
61+
/**
62+
* A handler for tasks.
63+
*/
6864
export interface TaskQueueFunction {
6965
(req: Request, res: express.Response): Promise<void>;
7066

67+
/** @alpha */
7168
__trigger: unknown;
69+
70+
/** @alpha */
7271
__endpoint: ManifestEndpoint;
72+
73+
/** @alpha */
7374
__requiredAPIs?: ManifestRequiredAPI[];
7475

76+
/**
77+
* The callback passed to the `TaskQueueFunction` constructor.
78+
* @param data - The body enqueued into a task queue.
79+
* @param context - The request context of the enqueued task
80+
* @returns Any return value. Google Cloud Functions will await any promise
81+
* before shutting down your function. Resolved return values
82+
* are only used for unit testing purposes.
83+
*/
7584
run(data: any, context: TaskContext): void | Promise<void>;
7685
}
7786

78-
/** @hidden */
87+
/**
88+
* Builder for creating a `TaskQueueFunction`.
89+
*/
7990
export class TaskQueueBuilder {
8091
/** @internal */
8192
constructor(
8293
private readonly tqOpts?: TaskQueueOptions,
8394
private readonly depOpts?: DeploymentOptions
8495
) {}
8596

97+
/**
98+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
99+
* @param handler - A callback to handle task requests.
100+
* @returns A Cloud Function you can export and deploy.
101+
*/
86102
onDispatch(
87103
handler: (data: any, context: TaskContext) => void | Promise<void>
88104
): TaskQueueFunction {
@@ -137,8 +153,8 @@ export class TaskQueueBuilder {
137153

138154
/**
139155
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
140-
* @param options Configuration for the Task Queue that feeds into this function.
141-
* @hidden
156+
* @param options - Configuration for the Task Queue that feeds into this function.
157+
* Omitting options will configure a Task Queue with default settings.
142158
*/
143159
export function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder {
144160
return new TaskQueueBuilder(options);

src/v2/providers/tasks.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
import * as options from '../options';
3636
import { HttpsFunction } from './https';
3737

38-
export { AuthData, RateLimits, Request, RetryConfig as RetryPolicy };
38+
export { AuthData, RateLimits, Request, RetryConfig };
3939

4040
export interface TaskQueueOptions extends options.EventHandlerOptions {
4141
/** How a task should be retried in the event of a non-2xx return. */
@@ -47,7 +47,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
4747
/**
4848
* Who can enqueue tasks for this function.
4949
* If left unspecified, only service accounts which have
50-
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
50+
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
5151
* will have permissions.
5252
*/
5353
invoker?: 'private' | string | string[];
@@ -146,15 +146,38 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
146146
retry?: boolean;
147147
}
148148

149+
/**
150+
* A handler for tasks.
151+
* @typeParam T - The task data interface. Task data is unmarshaled from JSON.
152+
*/
149153
export interface TaskQueueFunction<T = any> extends HttpsFunction {
150-
run(data: Request<T>): void | Promise<void>;
154+
/**
155+
* The callback passed to the `TaskQueueFunction` constructor.
156+
* @param request - A TaskRequest containing data and auth information.
157+
* @returns Any return value. Google Cloud Functions will await any promise
158+
* before shutting down your function. Resolved return values
159+
* are only used for unit testing purposes.
160+
*/
161+
run(request: Request<T>): void | Promise<void>;
151162
}
152163

153-
/** Handle a request sent to a Cloud Tasks queue. */
164+
/**
165+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
166+
* @param handler - A callback to handle task requests.
167+
* @typeParam Args - The interface for the request's `data` field.
168+
* @returns A Cloud Function you can export and deploy.
169+
*/
154170
export function onTaskDispatched<Args = any>(
155171
handler: (request: Request<Args>) => void | Promise<void>
156172
): TaskQueueFunction<Args>;
157-
/** Handle a request sent to a Cloud Tasks queue. */
173+
174+
/**
175+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
176+
* @param options - Configuration for the task queue or Cloud Function.
177+
* @param handler - A callback to handle task requests.
178+
* @typeParam Args - The interface for the request's `data` field.
179+
* @returns A Cloud Function you can export and deploy.
180+
*/
158181
export function onTaskDispatched<Args = any>(
159182
options: TaskQueueOptions,
160183
handler: (request: Request<Args>) => void | Promise<void>

0 commit comments

Comments
 (0)