Skip to content

Commit 73c5a96

Browse files
authored
Revert "Allow specifying failure policies (#482)"
This reverts commit 8039e02.
1 parent 8039e02 commit 73c5a96

File tree

6 files changed

+82
-212
lines changed

6 files changed

+82
-212
lines changed

changelog.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
feature - Allow specifying retry policies for event triggered functions.

spec/function-builder.spec.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,14 @@ describe('FunctionBuilder', () => {
7979
it('should allow valid runtime options to be set', () => {
8080
const fn = functions
8181
.runWith({
82-
failurePolicy: { retry: {} },
83-
memory: '256MB',
8482
timeoutSeconds: 90,
83+
memory: '256MB',
8584
})
8685
.auth.user()
8786
.onCreate((user) => user);
8887

8988
expect(fn.__trigger.availableMemoryMb).to.deep.equal(256);
9089
expect(fn.__trigger.timeout).to.deep.equal('90s');
91-
expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} });
92-
});
93-
94-
it("should apply a default failure policy if it's aliased with `true`", () => {
95-
const fn = functions
96-
.runWith({
97-
failurePolicy: true,
98-
memory: '256MB',
99-
timeoutSeconds: 90,
100-
})
101-
.auth.user()
102-
.onCreate((user) => user);
103-
104-
expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} });
10590
});
10691

10792
it('should allow both supported region and valid runtime options to be set', () => {
@@ -147,26 +132,7 @@ describe('FunctionBuilder', () => {
147132
functions
148133
.region('asia-northeast1')
149134
.runWith({ timeoutSeconds: 600, memory: '256MB' });
150-
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');
151-
});
152-
153-
it('should throw an error if user chooses a failurePolicy which is neither an object nor a boolean', () => {
154-
expect(() =>
155-
functions.runWith({
156-
failurePolicy: (1234 as unknown) as functions.RuntimeOptions['failurePolicy'],
157-
})
158-
).to.throw(
159-
Error,
160-
'RuntimeOptions.failurePolicy must be a boolean or an object'
161-
);
162-
});
163-
164-
it('should throw an error if user chooses a failurePolicy.retry which is not an object', () => {
165-
expect(() =>
166-
functions.runWith({
167-
failurePolicy: { retry: (1234 as unknown) as object },
168-
})
169-
).to.throw(Error, 'RuntimeOptions.failurePolicy.retry');
135+
}).to.throw(Error, 'TimeoutSeconds');
170136
});
171137

172138
it('should throw an error if user chooses an invalid memory allocation', () => {
@@ -188,13 +154,13 @@ describe('FunctionBuilder', () => {
188154
return functions.runWith({
189155
timeoutSeconds: 1000000,
190156
} as any);
191-
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');
157+
}).to.throw(Error, 'TimeoutSeconds');
192158

193159
expect(() => {
194160
return functions.region('asia-east2').runWith({
195161
timeoutSeconds: 1000000,
196162
} as any);
197-
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');
163+
}).to.throw(Error, 'TimeoutSeconds');
198164
});
199165

200166
it('should throw an error if user chooses an invalid region', () => {

spec/providers/auth.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ describe('Auth Functions', () => {
197197
});
198198

199199
describe('#onDelete', () => {
200-
const cloudFunctionDelete: CloudFunction<firebase.auth.UserRecord> = functions.handler.auth.user.onDelete(
200+
const cloudFunctionDelete: CloudFunction<
201+
firebase.auth.UserRecord
202+
> = functions.handler.auth.user.onDelete(
201203
(data: firebase.auth.UserRecord) => data
202204
);
203205

src/cloud-functions.ts

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@
2222

2323
import { Request, Response } from 'express';
2424
import * as _ from 'lodash';
25-
import {
26-
DEFAULT_FAILURE_POLICY,
27-
DeploymentOptions,
28-
FailurePolicy,
29-
MEMORY_LOOKUP,
30-
Schedule,
31-
} from './function-configuration';
25+
import { DeploymentOptions, Schedule } from './function-configuration';
3226
export { Request, Response };
3327

3428
/** @hidden */
@@ -208,7 +202,6 @@ export namespace Change {
208202
if (json.fieldMask) {
209203
before = applyFieldMask(before, json.after, json.fieldMask);
210204
}
211-
212205
return Change.fromObjects(
213206
customizer(before || {}),
214207
customizer(json.after || {})
@@ -223,16 +216,14 @@ export namespace Change {
223216
) {
224217
const before = _.assign({}, after);
225218
const masks = fieldMask.split(',');
226-
227-
masks.forEach((mask) => {
219+
_.forEach(masks, (mask) => {
228220
const val = _.get(sparseBefore, mask);
229221
if (typeof val === 'undefined') {
230222
_.unset(before, mask);
231223
} else {
232224
_.set(before, mask, val);
233225
}
234226
});
235-
236227
return before;
237228
}
238229
}
@@ -262,7 +253,6 @@ export interface TriggerAnnotated {
262253
resource: string;
263254
service: string;
264255
};
265-
failurePolicy?: FailurePolicy;
266256
httpsTrigger?: {};
267257
labels?: { [key: string]: string };
268258
regions?: string[];
@@ -322,40 +312,6 @@ export interface MakeCloudFunctionArgs<EventData> {
322312
triggerResource: () => string;
323313
}
324314

325-
/** @hidden */
326-
export function optionsToTrigger({
327-
failurePolicy: failurePolicyOrAlias,
328-
memory,
329-
regions,
330-
schedule,
331-
timeoutSeconds,
332-
}: DeploymentOptions): TriggerAnnotated['__trigger'] {
333-
/*
334-
* FailurePolicy can be aliased with a boolean value in the public API.
335-
* Convert aliases `true` and `false` to a standardized interface.
336-
*/
337-
const failurePolicy: FailurePolicy | undefined =
338-
failurePolicyOrAlias === false
339-
? undefined
340-
: failurePolicyOrAlias === true
341-
? DEFAULT_FAILURE_POLICY
342-
: failurePolicyOrAlias;
343-
344-
const availableMemoryMb: number | undefined =
345-
memory === undefined ? undefined : MEMORY_LOOKUP[memory];
346-
347-
const timeout: string | undefined =
348-
timeoutSeconds === undefined ? undefined : `${timeoutSeconds}s`;
349-
350-
return {
351-
...(failurePolicy === undefined ? {} : { failurePolicy }),
352-
...(availableMemoryMb === undefined ? {} : { availableMemoryMb }),
353-
...(regions === undefined ? {} : { regions }),
354-
...(schedule === undefined ? {} : { schedule }),
355-
...(timeout === undefined ? {} : { timeout }),
356-
};
357-
}
358-
359315
/** @hidden */
360316
export function makeCloudFunction<EventData>({
361317
after = () => {},
@@ -507,3 +463,28 @@ function _detectAuthType(event: Event) {
507463
}
508464
return 'UNAUTHENTICATED';
509465
}
466+
467+
/** @hidden */
468+
export function optionsToTrigger(options: DeploymentOptions) {
469+
const trigger: any = {};
470+
if (options.regions) {
471+
trigger.regions = options.regions;
472+
}
473+
if (options.timeoutSeconds) {
474+
trigger.timeout = options.timeoutSeconds.toString() + 's';
475+
}
476+
if (options.memory) {
477+
const memoryLookup = {
478+
'128MB': 128,
479+
'256MB': 256,
480+
'512MB': 512,
481+
'1GB': 1024,
482+
'2GB': 2048,
483+
};
484+
trigger.availableMemoryMb = _.get(memoryLookup, options.memory);
485+
}
486+
if (options.schedule) {
487+
trigger.schedule = options.schedule;
488+
}
489+
return trigger;
490+
}

0 commit comments

Comments
 (0)