I need to execute a function after the configuration and dependency injection has finished when the function app is loaded. Is there something similar to FunctionsStartup or a function trigger to achieve this?
The code I need to run relies on the database context so I can't use that without introducing circular dependencies.
There are no pre or post invocations available for Azure Functions. It would violate the serverless design. Function invocations are meant to be independent from each other, so there is no way to guarantee that some code is executed only once.
Circular dependencies can be avoided by carefully designing the Azure Function references. We can think of implementing stateful functions using Durable Functions.
You can check this durable function documentation for more information.
To initialize the dependencies, you can also check this Use dependency injection in .NET Azure Functions document.
Related
I am using Google Firebase Cloud Functions with TypeScript, and I found out that even though each function is deployed separately, they all share the same bundles and dependencies, even if some functions do not use them nor import them.
In my case, one cloud function uses Redis and others don't. I have 10 functions. All 10 functions actually end up importing redis related code even though they don't import them.
Since all functions share the same entry point, index.js. It currently seems it's impossible to have separate tree-shaken bundles / entry points for each function.
This is very inefficient in terms of bundle size / cold start timing / memory / etc. It also means as I have more and more functions, bundle size will grow for all functions together. It's not scalable.
Is there any way to not share the entry point, index.js, and have completely separate bundles by using bundlers like webpack?
You can create a different local Firebase working area (with firebase init) for each function that should deploy in isolation from the others. You will have to instruct the CLI not to overwrite the other functions on deployment using the --only functions:yourFunctionName to deploy it.
Or, you can deploy function using Cloud tools (gcloud) instead of Firebase tools, but you won't be able to use firebase-functions and its TypeScript bindings.
Or, you can lazily load your modules instead of statically loading them at the global scope of your functions, as described in this video.
I don't recommend using webpack. It's not going to be worth your time to get it configured.
You might try better-firebase-functions, which solves this elegantly by automatically lazy loading only the function that is currently invoked by checking the environment variable FUNCTION_NAME - see https://link.medium.com/4g3CJOLXidb
The iOS SDK of Firebase provides the function FIRApp.deleteApp which, according to the documentation:
Cleans up the current FIRApp, freeing associated data and returning its name to the pool for future use.
A similar function is available in the JavaScript SDK but not in the Java or C++ ones.
What this function does and when should I use it?
My understanding is that this function works as a destructor and thus I am supposed to call it when my app is closing. Is it correct? Should I call it on FIRApp.defaultApp too?
A FIRApp object contains references to the configuration data of your Firebase project. It is a lightweight object, mostly using a bit of memory keep those settings available when your application needs them.
Most applications create only a single FIRApp instance for the entire duration of their lifecycle. In such cases the resources will be automatically released when the application exists, and there is no need to explicitly delete the FIRApp instance.
I want the methods to be available only for tests, and not in application code. For example, a method to delete any user. I don't want this capability in production code. But it's helpful in test code.
How would I add provide such a method in a test context while keeping it out of production code?
Here's one possible solution:
Let's assume you create a package called test-helpers. In it, you create a function called removeAllUsers in the TestHelpers namespace.
Now in another package that needs TestHelpers.removeAllUsers, you can just do this:
Package.onTest(function(api) {
api.use('TestHelpers', 'server');
});
Because we only included the package in onTest, it won't exist in your production code. Furthermore, we created a server-only function (not a method), so even if it did get exposed in production, it couldn't be called from a client.
In one vein of thought I would like to configure a build with a custom task that will serve instead of the test default task. I will not be registering it as an "sbt test framework" as I'd like to avoid the syntax, limitations and history that comes with that. For example I'd like more flexibility in formatting, storing and sending test results.
Would it be possible introducing an sbt task to mimic sbt's default test task, in the following essential senses:
depend on compilation
be a dependency for other tasks such as artifact publishing tasks, and have them depend on a success return value from it
be able to provide it with library dependencies which will be excluded from final publishable artifacts
be able to control it just like any other task dependency
etc
Alternatively, are you able to delineate the structure of the mostly undocumented sbt TestFramework interface to a level that it's straightforward having your own formatting, test output logic, and test results publishing code, in your TestFramework implementation? I have mostly failed locating scalaTest's implementation of it.
Thanks in advance for you answers on both techniques.
I use qtscript in an application to provide automation capabilities for various functions within the application.
To allow greater flexibility i need the possibility to execute other tools (commandline commands/applications) from the script and get their output (the application itself is not security relevant - so calling random code may be ok).
Is their a way to do this with the basic qtscript module or some 3rd party class that encapsulate this or do i have to do this on my own?
A process can be spawned via QProcess class. It also provides console I/O capabilities to fetch executed process output (standard and error).
You will need to have a wrapper class however, since QProcess cannot be exposed directly to script environment (e.g. it defines no public slots accessible to a script).
See Related discussion on qtcentre forum.