Archived Support Site

This support site is archived. You can view the old support discussions but you cannot post new discussions.

Background workers

To run background jobs on AppHarbor, simply add a console application to your solution and a background worker to your application subscription.

If you push code without a website, we'll automatically add a background worker to your application. If your project includes a website, you'll have to add the background worker manually by browsing to the "Subscription" page from the application dashboard.

Execution model

AppHarbor will launch and monitor all executables found in the build artifact (including references). If a process terminates with a non-zero exit code, it will be relaunched with a short delay. If the process terminates a zero exit code, we'll assume the process is done processing and not start it again until next time the application is deployed.

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).

Configuration transformation works as for websites, so all configuration variables and add-on configuration will be injected into .config files. Note that the build causes a config file re-name for console application config files so that the configuration file name will generally be ExecutableName.exe.config. If there's no matching transform for that, no transformation will take place. You can get around this renaming the transformation to match the runtime configuration file name.

Preventing executables from being deployed to background workers

You can stop executables from being deployed to background workers by including the following in the corresponding configuration file(s) for the executable(s) you don't want to run:

<configuration>
  <appSettings>
    <add key="appharbor.deploy_as_background_worker" value="false"/>
  </appSettings>
</configuration>

Disabling all background workers for a single application

If you go to your application dashboard and navigate to the "Subscription" page, you can scale down the number of background workers to zero. This will terminate all background worker processes.

Temporary files

Temporary files can be written to the _TemporaryFiles directory from your current directory. Use something similar to Path.Combine(Directory.GetCurrentDirectory(), "_TemporaryFiles") to access it.

Keep in mind that temporary files are wiped on each deployment.

Logging

All standard output and standard error is streamed directly to the built-in logging module along with detailed information about the operation of the process manager that runs with your background workers. You can log simply by writing to the console and all you exceptions will automatically be logged. You can find more information in the knowledge base article about logging.

Limitations

You should make sure that any application run by AppHarbor background workers is idempotent and that it can be run concurrently by multiple background workers without error. Even if you only add one background worker on AppHarbor, the platform may at times run multiple instances of your app, for example if a server is being taken down for maintenance or similar.