Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
33 changes: 0 additions & 33 deletions 2nd-gen/taskqueues-backup-images/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const {onRequest} = require("firebase-functions/v2/https");
const {initializeApp} = require("firebase-admin/app");
const {getFunctions} = require("firebase-admin/functions");
const {getStorage} = require("firebase-admin/storage");
const {GoogleAuth} = require("google-auth-library");
const logger = functions.logger;
const HttpsError = functions.https.HttpsError;
initializeApp();
Expand Down Expand Up @@ -99,41 +98,10 @@ exports.backupapod = onTaskDispatched(
});


let auth;

// [START v2GetFunctionUri]
/**
* Get the URL of a given v2 cloud function.
*
* @param {string} name the function's name
* @param {string} location the function's location
* @return {Promise<string>} The URL of the function
*/
async function getFunctionUrl(name, location="us-central1") {
if (!auth) {
auth = new GoogleAuth({
scopes: "https://www.googleapis.com/auth/cloud-platform",
});
}
const projectId = await auth.getProjectId();
const url = "https://cloudfunctions.googleapis.com/v2beta/" +
`projects/${projectId}/locations/${location}/functions/${name}`;

const client = await auth.getClient();
const res = await client.request({url});
const uri = res.data?.serviceConfig?.uri;
if (!uri) {
throw new Error(`Unable to retreive uri for function at ${url}`);
}
return uri;
}
// [END v2GetFunctionUri]

// [START v2EnqueueTasks]
exports.enqueuebackuptasks = onRequest(
async (_request, response) => {
const queue = getFunctions().taskQueue("backupapod");
const targetUri = await getFunctionUrl("backupapod");

const enqueues = [];
for (let i = 0; i <= BACKUP_COUNT; i += 1) {
Expand All @@ -149,7 +117,6 @@ exports.enqueuebackuptasks = onRequest(
queue.enqueue({date}, {
scheduleDelaySeconds,
dispatchDeadlineSeconds: 60 * 5, // 5 minutes
uri: targetUri,
}),
);
}
Expand Down
1 change: 0 additions & 1 deletion 2nd-gen/taskqueues-backup-images/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"dependencies": {
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.1",
"google-auth-library": "^8.6.0",
"node-fetch": "^2.6.7"
},
"devDependencies": {
Expand Down