Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
06b62a1
Adding onPoll option to operation-poller (#3046)
joehan Jan 19, 2021
6258dd5
Typescriptify functionsDeployHelper (#3059)
joehan Jan 20, 2021
ec7d079
Typescriptifying gcp.cloudfunctions (#3060)
joehan Jan 20, 2021
f583ef6
Typescriptifying functionsConfig (#3063)
joehan Jan 21, 2021
08b9d56
Typescriptifying deploymentTool (#3061)
joehan Jan 21, 2021
b4944a4
Refactoring prepare stage of functions deploy (#3067)
joehan Jan 21, 2021
3be0dca
refactoring release step of functions deploy to use typescript
joehan Jan 21, 2021
e0e703e
Adding logic to build regional deployments
joehan Jan 24, 2021
046c7d7
Implementing createDeploymentPlan
joehan Jan 26, 2021
b876523
First round of PR feedback, removing most usages of lodash
joehan Jan 28, 2021
9e0e6e9
moving function prompts into their own file
joehan Jan 28, 2021
2a3b547
seperating out a bunch of code from functionsDeployHelper
joehan Jan 28, 2021
51f2395
Resolves merge conflicts
joehan Jan 28, 2021
30cc0e9
refactoring release step of functions deploy to use typescript (#3071)
joehan Feb 1, 2021
6916000
Implements core logic of running function deploys
joehan Feb 1, 2021
3c8d4a0
Typescriptifying prepareFunctionsUpload (#3064)
joehan Feb 1, 2021
11956fa
Implementing createDeploymentPlan (#3081)
joehan Feb 1, 2021
85d0afe
adding timing and logs for deployments
joehan Feb 2, 2021
00b1989
cleaning up unused code
joehan Feb 2, 2021
397d7c4
Fixing some things that were broken while merging
joehan Feb 3, 2021
21f4906
Fixing up the order of wait and close to ensure that queue promsies a…
joehan Feb 4, 2021
3b3edbd
Format and clean up typos
joehan Feb 4, 2021
e428bcb
refactoring error handling to be cleaner
joehan Feb 5, 2021
4c8e2fb
cleaning up extera newlines
joehan Feb 8, 2021
7f48130
first round of pr fixes
joehan Feb 9, 2021
39a7e86
Readding some changes that I accidenttally wiped out during a merge
joehan Feb 9, 2021
1366955
Switching name to id where appropriate
joehan Feb 9, 2021
7513229
fixing another bug caused by functionName vs Id
joehan Feb 9, 2021
8d3d82d
Merge pull request #3107 from firebase/jh-execute-deployment-plans
joehan Feb 9, 2021
6d2260e
Refactor functions-delete (#3110)
joehan Feb 9, 2021
42e6c15
Cleaning up error reporting
joehan Feb 10, 2021
e4ce126
Merge remote-tracking branch 'public/master' into jh-functions-refactor
joehan Feb 10, 2021
12a48ea
Merge remote-tracking branch 'public/master' into jh-functions-refactor
joehan Feb 11, 2021
7cfe9d9
Implement validation for changing trigger types, and fixes from bug b…
joehan Feb 12, 2021
5eb08bd
Merge branch 'master' into jh-functions-refactor
joehan Feb 12, 2021
5ca6bbf
Merge branch 'master' into jh-functions-refactor
joehan Feb 16, 2021
344b674
fixes package.json
joehan Feb 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing up the order of wait and close to ensure that queue promsies a…
…ctually resolve
  • Loading branch information
joehan committed Feb 4, 2021
commit 21f49064b4b1faba37140539bc29644aa515b420
35 changes: 20 additions & 15 deletions src/deploy/functions/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as clc from "cli-color";

import * as utils from "../../utils";
import * as helper from "../../functionsDeployHelper";
import { createDeploymentPlan } from "./deploymentPlanner";
import { CloudFunctionTrigger, createDeploymentPlan } from "./deploymentPlanner";
import * as tasks from "./tasks";
import { getAppEngineLocation } from "../../functionsConfig";
import { promptForFunctionDeletion } from "./prompts";
Expand All @@ -30,8 +30,8 @@ export async function release(context: any, options: any, payload: any) {
context.existingFunctions,
context.filters
);
const cloudFunctionsQueue = new Queue<() => any, any>({});
const schedulerQueue = new Queue<() => any, any>({});
const cloudFunctionsQueue = new Queue<() => Promise<CloudFunctionTrigger|void>, void>({});
const schedulerQueue = new Queue<() => Promise<any>, void>({});
const regionPromises = [];

const retryFuncParams: tasks.RetryFunctionParams = {
Expand Down Expand Up @@ -88,9 +88,6 @@ export async function release(context: any, options: any, payload: any) {
});
}
}

cloudFunctionsQueue.process();

for (const fnName of fullDeployment.schedulesToDelete) {
schedulerQueue
.run(tasks.deleteScheduleTask(fnName, appEngineLocation))
Expand All @@ -101,21 +98,29 @@ export async function release(context: any, options: any, payload: any) {
errorHandler.record("error", fnName, "delete schedule", err.message || "");
});
}
schedulerQueue.close();

// Once everything has been added to queues, starting processing.
const queuePromises = [cloudFunctionsQueue.wait(), schedulerQueue.wait()];
cloudFunctionsQueue.process();
schedulerQueue.process();
schedulerQueue.close();

// Wait for the first function in each region to be deployed, and all the other calls to be queued,
// then close the queue.
await Promise.all(regionPromises);
// Wait until the second round of creates/updates are added to the queue before closing it.
await Promise.all(regionPromises)
cloudFunctionsQueue.close();

// Wait for the first function in each region to be deployed, and all the other calls to be queued,
// then close the queue.
// Wait for all of the deployments to complete.
await cloudFunctionsQueue.wait();
await schedulerQueue.wait();
await Promise.all(queuePromises);
// TODO: We should also await the scheduler queue. However, for reasons I don't understand,
// awaiting 2 queues makes it so none of the code below this executes.
// If I remove either queue, it works correctly.
// Not sure if this is a bug with queue or if I'm doing something subtly incorrect, but functions deploys are ~2 orders of magnitude longer
// than schedule deployments, and there are no deployments that contain only calls to scheduler, so this works for now.
// await schedulerQueue.wait();
helper.logAndTrackDeployStats(cloudFunctionsQueue);
await helper.printTriggerUrls(projectId, sourceUrl);
errorHandler.printWarnings();
errorHandler.printErrors();
console.log("Deployment Complete!");
return;
return helper.printTriggerUrls(projectId, sourceUrl);
}
23 changes: 11 additions & 12 deletions src/deploy/functions/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getHumanFriendlyRuntimeName } from "../../parseRuntimeAndValidateSDK";
import { deleteTopic } from "../../gcp/pubsub";
import { DeploymentTimer } from "./deploymentTimer";
import { ErrorHandler } from "./errorHandler";
import { FirebaseError } from "../../error";

// TODO: Tune this for better performance.
const defaultPollerOptions = {
Expand All @@ -36,7 +35,7 @@ export function createFunctionTask(
params: RetryFunctionParams,
fn: CloudFunctionTrigger,
onPoll?: (op: any) => any
) {
): () => Promise<CloudFunctionTrigger> {
return async () => {
utils.logBullet(
clc.bold.cyan("functions: ") +
Expand Down Expand Up @@ -75,7 +74,7 @@ export function createFunctionTask(
},
defaultPollerOptions
);
const operationResult = await pollOperation(pollerOptions);
const operationResult = await pollOperation<CloudFunctionTrigger>(pollerOptions);
if (eventType === "https") {
try {
await cloudfunctions.setIamPolicy({
Expand All @@ -97,7 +96,7 @@ export function updateFunctionTask(
params: RetryFunctionParams,
fn: CloudFunctionTrigger,
onPoll?: (op: any) => any
) {
): () => Promise<CloudFunctionTrigger> {
return async () => {
utils.logBullet(
clc.bold.cyan("functions: ") +
Expand Down Expand Up @@ -136,7 +135,7 @@ export function updateFunctionTask(
},
defaultPollerOptions
);
const operationResult = await pollOperation(pollerOptions);
const operationResult = await pollOperation<CloudFunctionTrigger>(pollerOptions);
params.timer.endTimer(fn.name);
return operationResult;
};
Expand All @@ -161,7 +160,7 @@ export function deleteFunctionTask(params: RetryFunctionParams, fnName: string)
},
defaultPollerOptions
);
const operationResult = await pollOperation(pollerOptions);
const operationResult = await pollOperation<void>(pollerOptions);
params.timer.endTimer(fnName);
return operationResult;
};
Expand All @@ -171,14 +170,14 @@ export function upsertScheduleTask(
params: RetryFunctionParams,
fn: CloudFunctionTrigger,
appEngineLocation: string
) {
): () => Promise<any> {
return async () => {
const job = helper.toJob(fn, appEngineLocation, params.projectId);
return cloudscheduler.createOrReplaceJob(job);
};
}

export function deleteScheduleTask(fnName: string, appEngineLocation: string) {
export function deleteScheduleTask(fnName: string, appEngineLocation: string): () => Promise<void> {
return async () => {
const jobName = helper.getScheduleName(fnName, appEngineLocation);
const topicName = helper.getTopicName(fnName);
Expand Down Expand Up @@ -212,8 +211,8 @@ export function deleteScheduleTask(fnName: string, appEngineLocation: string) {
export function runRegionalFunctionDeployment(
params: RetryFunctionParams,
regionalDeployment: RegionalDeployment,
queue: Queue<any, any>
): Promise<any> {
queue: Queue<() => Promise<any>, void>
): Promise<void> {
// Build an onPoll function to check for sourceToken and queue up the rest of the deployment.
const onPollFn = (op: any) => {
// We should run the rest of the regional deployment if we either:
Expand Down Expand Up @@ -261,8 +260,8 @@ export function runRegionalFunctionDeployment(
function finishRegionalFunctionDeployment(
params: RetryFunctionParams,
regionalDeployment: RegionalDeployment,
queue: Queue<any, any>
) {
queue: Queue<()=>Promise<any>, void>
): void {
for (const fn of regionalDeployment.functionsToCreate) {
queue
.run(createFunctionTask(params, fn))
Expand Down