
Run some API operations in a background context. This should prevent some of the SQLite "interrupted" errors, as those can occur when the context closes while a query is running. The API operations that Workers use are now mostly running in a separate background context, at least from the moment onward when they can run independently of the Worker connection.
18 lines
450 B
Go
18 lines
450 B
Go
package api_impl
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const bgContextTimeout = 10 * time.Second
|
|
|
|
// bgContext returns a background context for background processing. This
|
|
// context MUST be used when a database query is meant to be independent of any
|
|
// API call that triggered it.
|
|
func bgContext() (context.Context, context.CancelFunc) {
|
|
return context.WithTimeout(context.Background(), bgContextTimeout)
|
|
}
|