Firebase Function Initialisation Code #9142
Unanswered
Bradley-McCallion
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The way I understand it, the functions framework imports the modules where you’ve defined decorators (e.g. @https_fn.on_request, @firestore_fn.on_document_written), builds a small Flask app, then exposes these functions. This means there’s no “main script” entrypoint and so code in a global scope outside of a function will not get executed.
My specific use case is that I want to execute some additional initialisation code before spinning up the function when I start it
Specifically I would like to optionally attach a debugger when running locally with a parameter flag set so something like:
However, I cannot find anywhere I can put this code to ensure it is executed on startup. I have tried putting it at the very top of the
main.py
, putting in an__init__.py
, putting it in an@init
function, but nothing seems to work. The only way I can get this to work is by putting it inside a function itself. However, while this issue still exists: #6838, I would like to formalise this method across my codebases to allow for local debugging if necessary and plotting this around inside real function code isn't desirable.As well as the above it would be good if you could do things like initialise log level
logging.basicConfig(level=logging.INFO)
before serving the functions.Does anyone know if anything likethis is possible?
Beta Was this translation helpful? Give feedback.
All reactions