0

I am looking for the most relevant/robust way to resolve the current webjob name. I need it at both function execution time and host startup for registration purpose in my internal logic.

Webjob name is defined in Properties\webjob-publish-settings.json but this file is not deployed. I can't use it at runtime anymore.

Webjob binaries are all stored in a dedicated folder named according to the webjob name. It looked like the best way to resolve my issue. But after having a look at the SDK and this issue, I am unsure this solution could be broken by a future update.
Currently the SDK is retrieving the webjob name through an internal environment variable WEBJOBS_NAME defined in WebSitesKnownKeyNames class. Why does the SDK is relying on this instead of the folder name if it is a secure solution?
Also the linked issue state that renaming a webjob folder in order to rename th webjob itself is not supported and a proper solution is on its way.

Does any of you have already faced this issue and successfully solved it?

mathewc
  • 13,312
  • 2
  • 45
  • 53
GGirard
  • 1,145
  • 1
  • 13
  • 33

1 Answers1

3

Just use the WEBJOBS_NAME environment variable - that's the easiest and most reliable. The WebJobs SDK uses it for this reason, also the environment variable decouples the SDK from the specifics of the underlying core Kudu WebJobs implementation details like folder structure, etc. As you can see in the Kudu code here it sets this environment variable before running the job. So it's safe to use.

The issue you linked to about renames is Azure Functions specific. You're not using Azure Functions it looks like.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • Thanks for your feedback. I am just wondering why the Webjob SDK made [this class](https://github.com/Azure/azure-webjobs-sdk/blob/663a508e8a851629c26a51e7de3af36629dfd120/src/Microsoft.Azure.WebJobs.Protocols/WebSitesKnownKeyNames.cs#L14) internal in that case... – GGirard Apr 03 '17 at 16:23
  • No real reason other than to limit unecessary public surface area. It really is rare that anyone needs to use these. – mathewc Apr 03 '17 at 17:00
  • I did not apply your response in time and got bitten by my hack with the webjob folder name.This is definitely not the right way to do it due to https://github.com/projectkudu/kudu/wiki/WebJobs#webjob-working-directory. I missed the point that the current directory actually contains also a random temp folder name. Thanks again! – GGirard Jun 07 '17 at 22:18