Skip to content

Commit c9bc736

Browse files
inlinedtaeold
andauthored
Rename enqueue to dispatch to match API proposal (#1004)
* Rename enqueue to dispatch to match API proposal * Update src/common/providers/https.ts Co-authored-by: Daniel Lee <danielylee@google.com> * Update src/function-builder.ts Co-authored-by: Daniel Lee <danielylee@google.com> Co-authored-by: Daniel Lee <danielylee@google.com>
1 parent 38f1946 commit c9bc736

File tree

8 files changed

+42
-30
lines changed

8 files changed

+42
-30
lines changed

spec/common/providers/https.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ interface TaskTest {
166166

167167
// Runs a TaskTest test.
168168
async function runTaskTest(test: TaskTest): Promise<any> {
169-
const taskQueueFunctionV1 = https.onEnqueueHandler((data, context) => {
169+
const taskQueueFunctionV1 = https.onDispatchHandler((data, context) => {
170170
expect(data).to.deep.equal(test.expectedData);
171171
if (test.taskFunction) {
172172
test.taskFunction(data, context);
@@ -176,7 +176,7 @@ async function runTaskTest(test: TaskTest): Promise<any> {
176176
const responseV1 = await runHandler(taskQueueFunctionV1, test.httpRequest);
177177
expect(responseV1.status).to.equal(test.expectedStatus);
178178

179-
const taskQueueFunctionV2 = https.onEnqueueHandler((request) => {
179+
const taskQueueFunctionV2 = https.onDispatchHandler((request) => {
180180
expect(request.data).to.deep.equal(test.expectedData);
181181
if (test.taskFunction2) {
182182
test.taskFunction2(request);

spec/v1/providers/https.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('#onEnqueue', () => {
225225
},
226226
invoker: 'private',
227227
})
228-
.onEnqueue(() => {});
228+
.onDispatch(() => {});
229229
expect(result.__trigger).to.deep.equal({
230230
taskQueueTrigger: {
231231
rateLimits: {
@@ -252,7 +252,7 @@ describe('#onEnqueue', () => {
252252
memory: '256MB',
253253
})
254254
.https.taskQueue({ retryConfig: { maxAttempts: 5 } })
255-
.onEnqueue(() => null);
255+
.onDispatch(() => null);
256256

257257
expect(fn.__trigger).to.deep.equal({
258258
regions: ['us-east1'],
@@ -275,7 +275,7 @@ describe('#onEnqueue', () => {
275275
},
276276
};
277277
let done = false;
278-
const cf = https.taskQueue().onEnqueue((d, c) => {
278+
const cf = https.taskQueue().onDispatch((d, c) => {
279279
expect(d).to.equal(data);
280280
expect(c).to.deep.equal(context);
281281
done = true;
@@ -288,7 +288,7 @@ describe('#onEnqueue', () => {
288288
// Regression test for firebase-functions#947
289289
it('should lock to the v1 API even with function.length == 1', async () => {
290290
let gotData: Record<string, any>;
291-
const func = https.taskQueue().onEnqueue((data) => {
291+
const func = https.taskQueue().onDispatch((data) => {
292292
gotData = data;
293293
});
294294

spec/v2/providers/https.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('onTaskEnqueue', () => {
378378
});
379379

380380
it('should return a minimal trigger with appropriate values', () => {
381-
const result = https.onTaskEnqueue(() => {});
381+
const result = https.onTaskDispatched(() => {});
382382
expect(result.__trigger).to.deep.equal({
383383
apiVersion: 2,
384384
platform: 'gcfv2',
@@ -388,7 +388,7 @@ describe('onTaskEnqueue', () => {
388388
});
389389

390390
it('should create a complex trigger with appropriate values', () => {
391-
const result = https.onTaskEnqueue(
391+
const result = https.onTaskDispatched(
392392
{
393393
...FULL_OPTIONS,
394394
retryConfig: {
@@ -432,7 +432,7 @@ describe('onTaskEnqueue', () => {
432432
minInstances: 1,
433433
});
434434

435-
const result = https.onTaskEnqueue(
435+
const result = https.onTaskDispatched(
436436
{
437437
region: 'us-west1',
438438
minInstances: 3,
@@ -459,7 +459,7 @@ describe('onTaskEnqueue', () => {
459459
token: 'token',
460460
},
461461
};
462-
const cf = https.onTaskEnqueue((r) => {
462+
const cf = https.onTaskDispatched((r) => {
463463
expect(r.data).to.deep.equal(request.data);
464464
expect(r.auth).to.deep.equal(request.auth);
465465
});
@@ -468,7 +468,7 @@ describe('onTaskEnqueue', () => {
468468
});
469469

470470
it('should be an express handler', async () => {
471-
const func = https.onTaskEnqueue((request) => {});
471+
const func = https.onTaskDispatched((request) => {});
472472

473473
const req = new MockRequest(
474474
{
@@ -487,17 +487,17 @@ describe('onTaskEnqueue', () => {
487487

488488
// These tests pass if the code transpiles
489489
it('allows desirable syntax', () => {
490-
https.onTaskEnqueue<string>((request: https.TaskRequest<string>) => {
490+
https.onTaskDispatched<string>((request: https.TaskRequest<string>) => {
491491
// There should be no lint warnings that data is not a string.
492492
console.log(`hello, ${request.data}`);
493493
});
494-
https.onTaskEnqueue((request: https.TaskRequest<string>) => {
494+
https.onTaskDispatched((request: https.TaskRequest<string>) => {
495495
console.log(`hello, ${request.data}`);
496496
});
497-
https.onTaskEnqueue<string>((request: https.TaskRequest) => {
497+
https.onTaskDispatched<string>((request: https.TaskRequest) => {
498498
console.log(`hello, ${request.data}`);
499499
});
500-
https.onTaskEnqueue((request: https.TaskRequest) => {
500+
https.onTaskDispatched((request: https.TaskRequest) => {
501501
console.log(`Hello, ${request.data}`);
502502
});
503503
});

src/common/providers/https.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,28 @@ export interface CallableRequest<T = any> {
171171

172172
/** How a task should be retried in the event of a non-2xx return. */
173173
export interface TaskRetryConfig {
174-
// If left unspecified, will default to 3
174+
/**
175+
* Maximum number of times a request should be attempted.
176+
* If left unspecified, will default to 3.
177+
*/
175178
maxAttempts?: number;
176179

177-
// If left unspecified will default to 1hr
180+
/**
181+
* The maximum amount of time to wait between attempts.
182+
* If left unspecified will default to 1hr.
183+
*/
178184
maxBackoffSeconds?: number;
179185

180-
// If left unspecified will default to 16
186+
/**
187+
* The maximum number of times to double the backoff between
188+
* retries. If left unspecified will default to 16.
189+
*/
181190
maxDoublings?: number;
182191

183-
// If left unspecified will default to 100ms
192+
/**
193+
* The minimum time to wait between attempts. If left unspecified
194+
* will default to 100ms.
195+
*/
184196
minBackoffSeconds?: number;
185197
}
186198

@@ -818,7 +830,7 @@ function wrapOnCallHandler<Req = any, Res = any>(
818830
}
819831

820832
/** @internal */
821-
export function onEnqueueHandler<Req = any>(
833+
export function onDispatchHandler<Req = any>(
822834
handler: v1TaskHandler | v2TaskHandler<Req>
823835
): (req: Request, res: express.Response) => Promise<void> {
824836
return async (req: Request, res: express.Response): Promise<void> => {

src/function-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export class FunctionBuilder {
358358

359359
/**
360360
* Declares a task queue function for clients to call using a Firebase Admin SDK.
361-
* @param handler A method that takes a data and context and returns void or Promise<void>.
361+
* @param options Configurations for the task queue function.
362362
*/
363363
/** @hidden */
364364
taskQueue: (options?: https.TaskQueueOptions) => {

src/handler-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class HandlerBuilder {
9292
) => void | Promise<void>
9393
) {
9494
const builder = new https.TaskQueueBuilder();
95-
const func = builder.onEnqueue(handler);
95+
const func = builder.onDispatch(handler);
9696
func.__trigger = {};
9797
return func;
9898
},

src/providers/https.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
FunctionsErrorCode,
3434
HttpsError,
3535
onCallHandler,
36-
onEnqueueHandler,
36+
onDispatchHandler,
3737
Request,
3838
TaskContext,
3939
TaskRateLimits,
@@ -107,15 +107,15 @@ export class TaskQueueBuilder {
107107
private readonly depOpts?: DeploymentOptions
108108
) {}
109109

110-
onEnqueue(
110+
onDispatch(
111111
handler: (data: any, context: TaskContext) => void | Promise<void>
112112
): TaskQueueFunction {
113113
// onEnqueueHandler sniffs the function length of the passed-in callback
114114
// and the user could have only tried to listen to data. Wrap their handler
115115
// in another handler to avoid accidentally triggering the v2 API
116116
const fixedLen = (data: any, context: TaskContext) =>
117117
handler(data, context);
118-
const func: any = onEnqueueHandler(fixedLen);
118+
const func: any = onDispatchHandler(fixedLen);
119119

120120
func.__trigger = {
121121
...optionsToTrigger(this.depOpts || {}),

src/v2/providers/https.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
FunctionsErrorCode,
3434
HttpsError,
3535
onCallHandler,
36-
onEnqueueHandler,
36+
onDispatchHandler,
3737
Request,
3838
TaskRateLimits,
3939
TaskRequest,
@@ -227,17 +227,17 @@ export function onCall<T = any, Return = any | Promise<any>>(
227227
}
228228

229229
/** Handle a request sent to a Cloud Tasks queue. */
230-
export function onTaskEnqueue<Args = any>(
230+
export function onTaskDispatched<Args = any>(
231231
handler: (request: TaskRequest<Args>) => void | Promise<void>
232232
): TaskQueueFunction<Args>;
233233

234234
/** Handle a request sent to a Cloud Tasks queue. */
235-
export function onTaskEnqueue<Args = any>(
235+
export function onTaskDispatched<Args = any>(
236236
options: TaskQueueOptions,
237237
handler: (request: TaskRequest<Args>) => void | Promise<void>
238238
): TaskQueueFunction<Args>;
239239

240-
export function onTaskEnqueue<Args = any>(
240+
export function onTaskDispatched<Args = any>(
241241
optsOrHandler:
242242
| TaskQueueOptions
243243
| ((request: TaskRequest<Args>) => void | Promise<void>),
@@ -256,7 +256,7 @@ export function onTaskEnqueue<Args = any>(
256256
// onEnqueueHandler sniffs the function length to determine which API to present.
257257
// fix the length to prevent api versions from being mismatched.
258258
const fixedLen = (req: TaskRequest<Args>) => handler(req);
259-
const func: any = onEnqueueHandler(fixedLen);
259+
const func: any = onDispatchHandler(fixedLen);
260260

261261
Object.defineProperty(func, '__trigger', {
262262
get: () => {

0 commit comments

Comments
 (0)