typesense / firestore-typesense-search

Firebase Extension to automatically push Firestore documents to Typesense for full-text search with typo tolerance, faceting, and more
https://extensions.dev/extensions/typesense/firestore-typesense-search
Apache License 2.0
158 stars 34 forks source link

Backfill function attempts to rerun admin.initializeApp on rerun #6

Closed kylewill closed 3 years ago

kylewill commented 3 years ago

I ran backfill, had to fix a schema issue (preventing backfill from making updates) and re-ran backfill soon after.

Firebase Functions logs shows this error:

Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
    at FirebaseAppError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
    at FirebaseAppError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
    at new FirebaseAppError (/workspace/node_modules/firebase-admin/lib/utils/error.js:125:28)
    at FirebaseNamespaceInternals.initializeApp (/workspace/node_modules/firebase-admin/lib/firebase-namespace.js:65:23)
    at FirebaseNamespace.initializeApp (/workspace/node_modules/firebase-admin/lib/firebase-namespace.js:371:30)
    at /workspace/src/backfillToTypesenseFromFirestore.js:29:13
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:134:23)
    at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:199:28
    at processTicksAndRejections (internal/process/task_queues.js:95:5) 

Firebase functions can be re-used so admin.initializeApp ends up being called multiple times.

Submitting a PR here: https://github.com/typesense/firestore-typesense-search/pull/5