tag:support.appharbor.com,2010-11-23:/discussions/problems/94176-hostingenvironmentqueuebackgroundworkitem-method-actioncancellationtokenAppHarbor: Discussion 2017-12-30T01:15:45Ztag:support.appharbor.com,2010-11-23:Comment/443881462017-12-30T01:15:19Z2017-12-30T01:15:45ZHostingEnvironment.QueueBackgroundWorkItem Method (Action<CancellationToken>)<div><p>Hi,</p>
<p>It's supported in the sense that you can use it to queue items for processing in the background, but notably the application is usually shut down immediately after a platform-related shutdown (e.g. when the application is redeployed). For background processing I'd generally recommend using <a href="https://support.appharbor.com/kb/getting-started/background-workers">AppHarbor's background workers</a> combined with for instance a queue processing system.</p>
<p>That said, if your app (web or background worker) needs to perform certain tasks during shutdown we have a model for graceful worker shutdown is currently in beta. You're more than welcome to use it: AppHarbor will signal an upcoming shutdown of a worker process by simply writing a file to a know location that your application can monitor for changes. The location of the file to monitor is injected as an environment variable (<code>WORKER_SHUTDOWN_FILE</code>).</p>
<p>When the file is written your application has 10 seconds to release any resources and exit before it is forcibly terminated. Take a look <a href="https://gist.github.com/runesoerensen/bc2575d5c08610308ffb">at this Gist showing a simple worker that monitors the shutdown file and performs cleanup logic</a>.</p>
<p>Let me know if you hit any snags or have feedback on how the feature can be improved!</p>
<p>Best,<br>
Rune</p></div>rune