1
votes

node: 10

firebase-functions: 3.12.0

firebase-tools: 8.19.0

firebase-admin: 8.12.1

I'm having some issues with cloud firestore functions, it seems that cloud functions on my project are randomly deploying alone, I removed all possible service accounts from the project, and generated new ones, and nobody has those credentials to deploy the cloud functions. Yet, they still are deploying alone, many times, and the problem is that it seems to be messing the runtime proccess of the cloud functions, making some nasty and hard to debug problems in production.

Cloud functions LogsCloud functions Logs

Here you can see in the logs, how is it attempting to deploy 2 times in a second, and then it completes the deploy, I will aprecciate so much any advice or tip you can give me.

const admin = require('firebase-admin');

// Production environment
const serviceAccount = require('./sc-prod.json');
console.log('You are deploying in PROD!');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'DATABASE_URL_HERE' // I have the database url correctly provided here
});


const createAffiliate = require('./createAffiliate');
const createEmployee = require('./createEmployee');
const createJob = require('./createJob');
const completeRechargedTransactions = require('./completeRechargedTransactions');
const createRequest = require('./createRequest');
const createUserAddress = require('./createUserAddress');
const createUser = require('./createUser');
const createProduct = require('./createProduct');
const createTransactions = require('./createTransactions');
const deleteUserAddress = require('./deleteUserAddress');
const recoverPaymentPin = require('./recoverPaymentPin');
const updateAffiliate = require('./updateAffiliate');
const updateEmployee = require('./updateEmployee');
const updateUser = require('./updateUser');
const updateTransactions = require('./updateTransactions');
const updateFCMTokens = require('./updateFCMTokens');
const updateProduct = require('./updateProduct');
const updateSubproduct = require('./updateSubproduct');
const updateRequest = require('./updateRequest');
const updateUserAddress = require('./updateUserAddress');
const updateUnitsSold = require('./updateUnitsSold');
const updateTransactionsCompleted = require('./updateTransactionsCompleted');
const updateQRCode = require('./updateQRCode');
const migrateData = require('./migrateData');
const updatePaymentTypePercentages = require('./updatePaymentTypePercentages');
const createMessage = require('./createMessage');
const referUser = require('./referUser');
const updatePaymentPin = require('./updatePaymentPin');
const takeDeliveryRequest = require('./takeDeliveryRequest');
const fetchAffiliateByEmail = require('./fetchAffiliateByEmail');
const processTransaction = require('./processTransaction');
const processCart = require('./processCart');
const processPayment = require('./processPayment');
const scheduledFirestoreExport = require('./scheduledFirestoreExport');
const sendTransactionNotifications = require('./sendTransactionNotifications');
const sendRequestNotifications = require('./sendRequestNotifications');
const setCurrentSession = require('./setCurrentSession');
const storeReferral = require('./storeReferral');
const submitSurvey = require('./submitSurvey');
const setCurrentAddress = require('./setCurrentAddress');
const sendNewsNotification = require('./sendNewsNotification');
const aggregateProduct = require('./aggregateProduct');
const validateMarketProfile = require('./validateMarketProfile');
const writeMarketCategory = require('./writeMarketCategory');
const writeCategory = require('./writeCategory');
const createAffiliateOnly = require('./createAffiliateOnly');
const updateAffiliateOnly = require('./updateAffiliateOnly');

exports.createAffiliate = createAffiliate.createAffiliate;
exports.createEmployee = createEmployee.createEmployee;
exports.createJob = createJob.createJob;
exports.completeRechargedTransactions =
  completeRechargedTransactions.completeRechargedTransactions;
exports.createUser = createUser.createUser;
exports.createProduct = createProduct.createProduct;
exports.createRequest = createRequest.createRequest;
exports.createUserAddress = createUserAddress.createUserAddress;
exports.createTransactions = createTransactions.createTransactions;
exports.deleteUserAddress = deleteUserAddress.deleteUserAddress;
exports.processPayment = processPayment.processPayment;
exports.processCart = processCart.processCart;
exports.recoverPaymentPin = recoverPaymentPin.recoverPaymentPin;
exports.takeDeliveryRequest = takeDeliveryRequest.takeDeliveryRequest;
exports.scheduledFirestoreExport =
  scheduledFirestoreExport.scheduledFirestoreExport;
exports.sendTransactionNotifications =
  sendTransactionNotifications.sendTransactionNotifications;
exports.sendRequestNotifications =
  sendRequestNotifications.sendRequestNotifications;
exports.setCurrentSession = setCurrentSession.setCurrentSession;
exports.storeReferral = storeReferral.storeReferral;
exports.updateAffiliate = updateAffiliate.updateAffiliate;
exports.updateEmployee = updateEmployee.updateEmployee;
exports.updateUser = updateUser.updateUser;
exports.updateProduct = updateProduct.updateProduct;
exports.updateSubproduct = updateSubproduct.updateSubproduct;
exports.updateRequest = updateRequest.updateRequest;
exports.updateFCMTokens = updateFCMTokens.updateFCMTokens;
exports.migrateData = migrateData.migrateData;
exports.updateUserAddress = updateUserAddress.updateUserAddress;
exports.updateUnitsSold = updateUnitsSold.updateUnitsSold;
exports.updateTransactions = updateTransactions.updateTransactions;
exports.updateTransactionsCompleted =
  updateTransactionsCompleted.updateTransactionsCompleted;
exports.updateQRCode = updateQRCode.updateQRCode;
exports.updatePaymentTypePercentages =
  updatePaymentTypePercentages.updatePaymentTypePercentages;
exports.createMessage = createMessage.createMessage;
exports.referUser = referUser.referUser;
exports.updatePaymentPin = updatePaymentPin.updatePaymentPin;
exports.fetchAffiliateByEmail = fetchAffiliateByEmail.fetchAffiliateByEmail;
exports.processTransaction = processTransaction.processTransaction;
exports.submitSurvey = submitSurvey.submitSurvey;
exports.setCurrentAddress = setCurrentAddress.setCurrentAddress;
exports.sendNewsNotification = sendNewsNotification.sendNewsNotification;
exports.aggregateProduct = aggregateProduct.aggregateProduct;
exports.validateMarketProfile = validateMarketProfile.validateMarketProfile;
exports.writeMarketCategory = writeMarketCategory.writeMarketCategory;
exports.writeCategory = writeCategory.writeCategory;
exports.createAffiliateOnly = createAffiliateOnly.createAffiliateOnly;
exports.updateAffiliateOnly = updateAffiliateOnly.updateAffiliateOnly;

console.log('Deploy is complete!');

And here is the index.js file where all cloud functions are imported

1

1 Answers

1
votes

The problem isn't that functions are being deployed randomly. The problem is that you have a console log at the root level of your index.js. This line of code is going to execute every time a function is loaded into a new server instance allocated by Cloud Functions:

console.log('Deploy is complete!');

Cloud Functions allocates and deallocates server instances as it sees fit to handle your functions' traffic, so I would expect that line of code to appear from time to time for each and every one of your functions exported here, as they all execute the same code at the global scope.

I suggest removing it, as it doesn't really add helpful information, given the way that global code works in Cloud Functions.