Doing cleanup when using Sessions

If I create a temporary directory on a worker using the Session API (think the file processing example but everything is going in a temporary directory), how can I guarantee deleting the temporary directory when the workflow succeeds/fails/gets cancelled?

I see on that I can use defer to run a workflow, but if I use the disconnected context will it run on the same worker that the session was started on?


I think in this case you want to run the whole session in a disconnected context and use some other mechanism to notify activities in the session that cancellation has happened.

I filed an issue to come up with cleaner design.

The most straightforward way I know of is by creating a host specific taskqueue on each worker and then passing that to the context when you invoke the cleanup activity. There is a decent example in the Java version of the file processing code:

Using the per-host taskqueue makes this possible.