Skip to main content
Version: Current (v17+)

Background Processing

By default, a uSync report, import or export runs from your browser. The uSync dashboard asks the server to process one handler at a time and waits for each step to finish before starting the next, so you stay on the dashboard until the run is complete.

Background processing mode hands the whole run to the server instead. You start it from the dashboard as usual, and you can then move around the backoffice while it runs.

The setting is in appsettings.json:

appsettings.json
"uSync": {
"Settings": {
"ProcessingMode": "Background"
}
}
ValueDetails
Normal(default) The browser runs each step in turn. You stay on the uSync dashboard for the whole run.
BackgroundThe run happens on the server as one long-running operation. You can leave the dashboard while it runs.
warning

Background mode is opt in. It is safe to use on SQL Server, but on SQLite it can cause other backoffice requests to fail while a large import is running. Read the SQLite section before you turn it on.

How it works​

In background mode, uSync starts the run using Umbraco's long-running operation service and returns straight away. The dashboard then follows the progress of the run:

  • Progress and completion are pushed to the browser over SignalR when it is available.
  • If SignalR isn't delivering updates, the dashboard falls back to asking the server for the status of the run.
  • If you reload the page, or come back to the uSync dashboard later, it reconnects to the run that is still going.

Only one run of each action (report, import or export) can happen at a time. If you start a second import while one is already running, uSync rejects it rather than running the two side by side.

A background run can't be cancelled once it has started.

SQLite​

Background mode is not safe by default on SQLite sites.

The default SQLite connection string that Umbraco uses includes Cache=Shared. With a shared cache, SQLite locks whole tables while it writes. A long background import can hold those locks for most of the run, and in background mode you (or other editors) are free to use the backoffice at the same time.

Any other backoffice request made during that time can wait on the lock and then fail with:

SQLite Error 6: 'database table is locked'

This includes requests that have nothing to do with uSync, such as the check Umbraco makes on your login token for every backoffice request.

This error is not data corruption. The uSync run itself will still complete, or fail cleanly and report the failure on the dashboard.

If you want to use background mode on SQLite:

  • Remove Cache=Shared from the connection string. SQLite then uses file-level locks, where a busy request waits briefly instead of failing. This reduces the problem, but a large import can still slow other requests down.
  • Check WAL journal mode is on. WAL mode lets readers carry on alongside a writer far better than the default journal mode. Umbraco sets this when it creates the database.
  • Run large imports in a quiet period. For a first import or a big migration, pick a time when nobody else needs the backoffice.

If you can't do these, leave ProcessingMode set to Normal on SQLite sites.

If the Site Restarts During a Run​

If the site restarts while a background run is going (for example, the app pool recycles), the run is lost. Umbraco's record of it will still say it is running until it expires, which by default is 5 minutes (Umbraco's LongRunningOperations:ExpirationTime setting).

After a restart, the "running in background" banner on the uSync dashboard clears itself once that record expires, and you can then start a new run.

If you don't want to wait, the banner has a Not actually running? Reset this view button. This clears the banner in your browser and unlocks the dashboard. It can't end Umbraco's record of the run, so a new run started straight away may still be rejected as already running until the record expires.

Load-Balanced backoffice​

From Umbraco 17, you can load balance the backoffice. From uSync v17.4.0, uSync supports a load-balanced backoffice in Background mode only.

Load-balancing on Normal

Normal mode doesn't work with a load-balanced backoffice. Each step of a normal run is a separate request, and if the next request goes to a different server, those results are lost.

To run uSync in background mode across more than one backoffice server you need:

  • The uSync folder on shared or replicated storage. uSync reads and writes files on disk for imports, exports and uploaded zip files. If each server has its own copy of the folder, a file written on one server can't be seen by the others.
  • Isolated caches set to load balance. Call umbracoBuilder.LoadBalanceIsolatedCaches() in a composer, as Umbraco's load-balancing docs require. Without it, changes made by an import on one server won't show on another until its cache expires.

SignalR is optional. With a SignalR backplane (SQL Server or Redis) and sticky sessions, or with Azure SignalR, you get live progress whichever server you are connected to. Without one, uSync falls back to checking the status of the run.

When the status is read from a server other than the one doing the work, the dashboard shows the handler summaries while the run is going. The full list of results appears when the run completes.