Great post, gave me some pointers.
I was trying to interact with my main python app services app, in particular use the virtual environment for this. Thought I would share my hacky way to get this all running for feedback and hopefully it might help people.
What I learned:
Deploying a webjob via the api requires a very specific url and headers to work. Documented in the kudu docs: https://github.com/projectkudu/kudu/wiki/WebJobs-API
This worked for me:
curl -X PUT -T "webjob.zip" -u '<username>:<password>' -H "Content-Type: application/zip" -H "Content-Disposition: attachment; filename=run.sh" https://<appname<.scm.azurewebsites.net/api/triggeredwebjobs/<webjobname>
The settings.job file cannot have comments in it, this works:
{ "schedule": "0 */2 * * * *" }
When deploying a web job, it copies the zip to and unpacks here: /home/site/wwwroot/App_Data/jobs/triggered/
I was expecting it to be able to run my python script from here, however the python virtual environment isn't activated so it cannot find the python executable, and even if you specify it, it cannot access my main app dependencies.
Python executable is located here: /opt/python/3/bin/python, however this is not in the path of the user executing the webjob.
In any case I need to activate the virtual environment used by my app. Through the ssh shell, I identified that the virtual environment path is /tmp/<random chars>/antenv
This path is available as a session variable VIRTUALENVIRONMENT_PATH through SSH, but not available to the user running the webjob.
So this is where I am at currently, and this seems to do what I need:
#!/bin/bash
VIRTUALENVIRONMENT_PATH=$(find /tmp -type d -name antenv -print -quit 2>/dev/null)
echo "Python path: $(which python)"
echo "Virtual environment path: $VIRTUALENVIRONMENT_PATH"
echo "Setting up virtual environment"
source $VIRTUALENVIRONMENT_PATH/bin/activate
#main python file
python webjob.py
deactivate