Sample WebApp and WebJob in python hosted via Azure App Service.
This consists of a Flask App that will place jobs in an Azure Service Bus Queue along with a Worker (WebJob) that processes items on the Service Bus Queue.
- Create a
config.yml
file in the project root - next todeploy.cmd
.
- A full example file can be found at the bottom of this readme
- Create Service Bus Namespace
- Put the name in
config.yml
under keySERVICE_BUS_NAMESPACE
- Create Service Bus Queue under the namespace
- Put the queue name in
config.yml
underSERVICE_BUS_QUEUE_NAME
- Check Lock Duration timer and make sure it is 30 seconds
- Create a shared access policy named with properties send and listen
- Put the shared accesskey name & shared accesskey value in
config.yml
underSERVICE_BUS_QUEUE_ACCESS_KEY_NAME
,SERVICE_BUS_QUEUE_ACCESS_KEY_VALUE
- Finish preparing the
config.yml
with a few basic values:
LOCAL: True
SERVER_HOST: "localhost"
SERVER_PORT: 80
- To start the server, navigate to the project root and run
python runserver.py
- Open your webrowser and go to
http://localhost
You should see Hello, World! - Neviaget to
http://localhost/test
You should see a message being enqueued with the current timestamp.
- To start the worker, navigate to the project root and run
python runworker.py
- You should see a console trace immediately processing the message you previously sent
- Create a Resource Group in Azure RM
- Create App Service WebApp
- Set the Python Version in Settings -> Application Settings to 3.4
- Create WebJob for worker (under Settings -> WebJobs)
- Select the continuous WebJob option
- Upload a dummy file for now. (It must have a .exe, .py, etc. extension to upload)
- Take the WebJob name, and put this in
sampleapp.worker/__init__.py
asname = 'WHATEVER_NAME_YOU_CHOSE'
- Set environmental variables (from
config.yml
) in Settings -> Application Settings under app settings.
- Copy Key and Values from
config.yml
precisely. (Leave outLOCAL: True
from Azure though) - Don't use quotations when pasting values in Azure App Settings.
- Create deployment credentials (under Settings -> Publishing)
- Go to Deployment source and chose the source Local Git Repository
- Add this as a remote to your local git repo. Name this remote azure
git remote add azure https://[email protected]:443/NeedsMoreGit.git
- Deploy via
git push azure master
- If you rename the "sampleapp" python package, or the server/worker packages, you need to make the following changes.
- Replace all package imports with the new name. Don't forget to also replace
- deploy_job.py
- runserver.py
- runworker.py
- web.config:
- You should not modify ptvs_virtualenv_proxy.py
LOCAL: True
SERVICE_BUS_NAMESPACE: "serviceBusNameSpace"
SERVICE_BUS_QUEUE_NAME: "nameServiceBusQueue"
SERVICE_BUS_QUEUE_ACCESS_KEY_NAME: "whatevernameyouchoose"
SERVICE_BUS_QUEUE_ACCESS_KEY_VALUE: "yourkey!!"
SERVER_HOST: "localhost"
SERVER_PORT: 80