Is it possible to hook into the lifecycle of my Pu...
# getting-started
b
Is it possible to hook into the lifecycle of my Pulumi application? E.g. declare functions in my Pulumi codebase that get called on deployment start, on deployment finish?
l
Not in a generic way. There is a long-standing issue for this: https://github.com/pulumi/pulumi/issues/1691 There is already some support for executing commands using the
Command
package: https://www.pulumi.com/registry/packages/command/
b
I see.. My use case is just like this comment https://github.com/pulumi/pulumi/issues/1691#issuecomment-909083261, does the command package support this?
e
Command doesn't support that. You can hook startup pretty easily, just have some code at the start of your program and check if the dryRun flag is set (each SDK has a way to get this, something like
pulumi.runtime.dry_run
) There's currently nothing for seeing the end of a deployment. I've been re-thinking the engine/program communication protocol recently a bit, so I'll keep this in mind for any new designs.
b
I see, thanks, checking
dry_run
definitely works for the startup behavior. I'm going to give some of the Node.js exit handlers a try - I think the
exit
event would definitely work here, but that doesn't allow asynchronous work, so I'm hoping pulumi doesn't explicitly exit the process and I can use
beforeExit
e
I think you can use beforeExit. There's a few places we call exit directly but not once an update is running I believe.
Trouble is that just tells you the program has exited, not that the deployment is actually done. Your program could quit while pulumi is still doing queued operations.
👍 1