Azure Webjobs - light weight web worker roles
Azure websites Webjobs are currently in preview and they are nice way to have some light weight background
processing for your websites. You might have faced scenarios where you would have spin up threads to perform some background tasks in your website. That's not an ideal way so you used to have another option of having PaaS worker roles, but do we really need them for small tasks such as some aggregation of data, reporting or
log clean-up.
This is where Azure Webjobs come to rescue. They provide background processing for your websites. In other words we can call them - "light weight web worker role".
There are different
ways of scheduling jobs in Azure webjobs - we can schedule the jobs on daily, weekly basis or have them constant
running. Constantly running job, for example, will look at an activity running
in the website and react to it. It is kind of a trigger in websites. This is, basically,
a continuously running task or service.
Different kinds of
running modes that Webjobs provide:
- Triggered (Tasks)
- Invoked by user, or helper service (such as azure scheduler), which basically just triggers a job
- These are just Https protected by deployment credentials. For example, there can be a task to clean up logs that will require to visit a particular url protected by credentials and this will trigger the task. But in most cases one will not want to visit the site every time, so it might be done using a helper service.
- Instance used is determined by the software load balancer (configurable).
- Continuous (Service)
- Background service monitors running state and invokes if needed for jobs.
- AlwaysOn is a helper service that monitors the states and invokes, for VM. AlwaysOn basically does the same thing what a continuous service does for job, but it does it for a website. It monitors website and if it finds that website is down for some reason, it restarts it.
- Runs in all available instances, configurable to be a singleton
It is basically a
light weight web worker role, and we shouldn't do heavy tasks as it will run on top of
the website itself. Also, there's no point in
having a worker role just to run a 10 second jobs such as aggregation of data.
In this case webjobs are helpful. Webjobs is managed, so everything is much
easier to do. If you wanted to spin up a small application, you can do it within
1 minute using webjobs.
Websites are
basically a container for webjobs. Webjobs run outside
of your website and run parallel to w3wp process. Each job is a separate
process running in the VM.
No comments: