They're here! AppHarbor background workers are now in beta. To start running background tasks right now, go to your application's subscription page and add at least one background worker. The next time your application is deployed, AppHarbor will identify any
.exe files in the build output of your application and start running them. This makes running background tasks on AppHarbor as easy as adding a console application project to your solution. An example console app could look like this:
public static void main(String args)
When deciding how to support background tasks on AppHarbor, we wanted to take the same approach we used for ASP.NET apps: Make getting started as simple as possible and require as few modifications to your existing code as possible. That's why we settled on running .exe files found in the application build output.
Background workers share their configuration with web workers and can access application add-ons and other resources in the same way that web workers can. For existing AppHarbor applications there are no deployment changes until a background worker is added to the subscription. Once at least one background worker is added, then any .exe files will launched, and both web and background workers will be automatically updated when you push new versions of your code.
AppHarbor background workers are not only useful for running auxiliary tasks associated with web applications. You can use background workers to scale any .NET workload that can be run as an executable on AppHarbor. We're excited that background workers lets us expand the AppHarbor value proposition to whole new classes of .NET applications. We will continue to improve and expand the platform to let you run and scale any application on AppHarbor.
If you need additional control over what code AppHarbor runs in background workers, you can take advantage of the solution file convention to not build projects that you don't need AppHarbor to run. If we find an
.exe file with a corresponding
.exe.config file that has a
appharbor.deploy_as_background_worker appSetting set to
false, then that particular executable will be ignored.
Applications run in an AppHarbor background worker are isolated in the same way as ASP.NET applications run by web workers. All executables run by a single background worker compete for the same resource allocation (i.e. having multiple copies of the same executable run by a single background worker will not get you more resources). Note that the AppHarbor Terms Of Service prohibit creating multiple applications with the intent to scale without incurring any costs.
If your executable exits with a non-zero exit code, AppHarbor will restart the application. If the exit code is 0, the application will not be restarted, but it will be started again if a new version of your application is deployed.
We do not currently provide any logging of background worker console output, although that is on our TODO-list. The logging add-ons in the AppHarbor add-on catalog catalog will work for properly instrumented background worker applications.
As always, we can't wait to see how AppHarbor users will use this new feature and we welcome feedback and feature requests. If you encounter problems, then check please refer to the AppHarbor support page. Also check out the knowledge base article on background workers.
UPDATE: A screencast demonstrating how to create and deploy a background worker is now available here.