Sybren A. Stüvel 791d877ff1 Manager: implement API endpoint for deleting jobs
Implement the `deleteJob` API endpoint. Calling this endpoint will mark
the job as "deletion requested", after which it's queued for actual
deletion. This makes the API response fast, even when there is a lot of
work to do in the background.

A new background service "job deleter" keeps track of the queue of such
jobs, and performs the actual deletion. It removes:

- Shaman checkout for the job (but see below)
- Manager-local files of the job (task logs, last-rendered images)
- The job itself

The removal is done in the above order, so the job is only removed from the
database if the rest of the removal was succesful.

Shaman checkouts are only removed if the job was submitted with Flamenco
version 3.2. Earlier versions did not record enough information to reliably
do this.
2023-01-04 01:18:21 +01:00

54 lines
1.8 KiB
Go

package job_deleter
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"context"
"git.blender.org/flamenco/internal/manager/local_storage"
"git.blender.org/flamenco/internal/manager/persistence"
"git.blender.org/flamenco/internal/manager/webupdates"
"git.blender.org/flamenco/pkg/api"
"git.blender.org/flamenco/pkg/shaman"
)
// Generate mock implementations of these interfaces.
//go:generate go run github.com/golang/mock/mockgen -destination mocks/interfaces_mock.gen.go -package mocks git.blender.org/flamenco/internal/manager/job_deleter PersistenceService,Storage,ChangeBroadcaster,Shaman
type PersistenceService interface {
FetchJob(ctx context.Context, jobUUID string) (*persistence.Job, error)
RequestJobDeletion(ctx context.Context, j *persistence.Job) error
// FetchJobsDeletionRequested returns the UUIDs of to-be-deleted jobs.
FetchJobsDeletionRequested(ctx context.Context) ([]string, error)
DeleteJob(ctx context.Context, jobUUID string) error
}
// PersistenceService should be a subset of persistence.DB
var _ PersistenceService = (*persistence.DB)(nil)
type Storage interface {
// RemoveJobStorage removes from disk the directory for storing job-related files.
RemoveJobStorage(ctx context.Context, jobUUID string) error
}
var _ Storage = (*local_storage.StorageInfo)(nil)
type ChangeBroadcaster interface {
// BroadcastJobUpdate sends the job update to SocketIO clients.
BroadcastJobUpdate(jobUpdate api.SocketIOJobUpdate)
}
// ChangeBroadcaster should be a subset of webupdates.BiDirComms
var _ ChangeBroadcaster = (*webupdates.BiDirComms)(nil)
type Shaman interface {
// IsEnabled returns whether this Shaman service is enabled or not.
IsEnabled() bool
// EraseCheckout deletes the symlinks and the directory structure that makes up the checkout.
EraseCheckout(checkoutID string) error
}
var _ Shaman = (*shaman.Server)(nil)