mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Add task to copy files
This commit is contained in:
@ -50,6 +50,7 @@ trait BackendApp[F[_]] {
|
||||
def events: EventExchange[F]
|
||||
def notification: ONotification[F]
|
||||
def bookmarks: OQueryBookmarks[F]
|
||||
def fileRepository: OFileRepository[F]
|
||||
}
|
||||
|
||||
object BackendApp {
|
||||
@ -91,6 +92,7 @@ object BackendApp {
|
||||
)
|
||||
notifyImpl <- ONotification(store, notificationMod)
|
||||
bookmarksImpl <- OQueryBookmarks(store)
|
||||
fileRepoImpl <- OFileRepository(queue, joexImpl)
|
||||
} yield new BackendApp[F] {
|
||||
val pubSub = pubSubT
|
||||
val login = loginImpl
|
||||
@ -118,5 +120,6 @@ object BackendApp {
|
||||
val events = notificationMod
|
||||
val notification = notifyImpl
|
||||
val bookmarks = bookmarksImpl
|
||||
val fileRepository = fileRepoImpl
|
||||
}
|
||||
}
|
||||
|
@ -42,15 +42,11 @@ object Config {
|
||||
def defaultStoreConfig: FileStoreConfig =
|
||||
enabledStores(defaultStore)
|
||||
|
||||
def toFileRepositoryConfig: FileRepositoryConfig =
|
||||
defaultStoreConfig match {
|
||||
case FileStoreConfig.DefaultDatabase(_) =>
|
||||
FileRepositoryConfig.Database(chunkSize)
|
||||
case FileStoreConfig.S3(_, endpoint, accessKey, secretKey, bucket) =>
|
||||
FileRepositoryConfig.S3(endpoint, accessKey, secretKey, bucket, chunkSize)
|
||||
case FileStoreConfig.FileSystem(_, directory) =>
|
||||
FileRepositoryConfig.Directory(directory, chunkSize)
|
||||
}
|
||||
def defaultFileRepositoryConfig: FileRepositoryConfig =
|
||||
FileRepositoryConfig.fromFileStoreConfig(chunkSize, defaultStoreConfig)
|
||||
|
||||
def getFileRepositoryConfig(id: Ident): Option[FileRepositoryConfig] =
|
||||
stores.get(id).map(FileRepositoryConfig.fromFileStoreConfig(chunkSize, _))
|
||||
|
||||
def validate: ValidatedNec[String, Files] = {
|
||||
val storesEmpty =
|
||||
|
@ -15,6 +15,26 @@ import docspell.notification.api.PeriodicQueryArgs
|
||||
import docspell.store.records.RJob
|
||||
|
||||
object JobFactory extends MailAddressCodec {
|
||||
def fileCopy[F[_]: Sync](
|
||||
args: FileCopyTaskArgs,
|
||||
submitter: AccountId = DocspellSystem.account
|
||||
): F[RJob] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
job = RJob.newJob(
|
||||
id,
|
||||
FileCopyTaskArgs.taskName,
|
||||
submitter.collective,
|
||||
args,
|
||||
s"Copying all files",
|
||||
now,
|
||||
submitter.user,
|
||||
Priority.High,
|
||||
Some(FileCopyTaskArgs.taskName)
|
||||
)
|
||||
} yield job
|
||||
|
||||
def periodicQuery[F[_]: Sync](args: PeriodicQueryArgs, submitter: AccountId): F[RJob] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.backend.ops
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.backend.JobFactory
|
||||
import docspell.common.FileCopyTaskArgs
|
||||
import docspell.store.queue.JobQueue
|
||||
import docspell.store.records.RJob
|
||||
|
||||
trait OFileRepository[F[_]] {
|
||||
|
||||
/** Inserts the job or return None if such a job already is running. */
|
||||
def cloneFileRepository(args: FileCopyTaskArgs, notifyJoex: Boolean): F[Option[RJob]]
|
||||
}
|
||||
|
||||
object OFileRepository {
|
||||
|
||||
def apply[F[_]: Async](
|
||||
queue: JobQueue[F],
|
||||
joex: OJoex[F]
|
||||
): Resource[F, OFileRepository[F]] =
|
||||
Resource.pure(new OFileRepository[F] {
|
||||
def cloneFileRepository(
|
||||
args: FileCopyTaskArgs,
|
||||
notifyJoex: Boolean
|
||||
): F[Option[RJob]] =
|
||||
for {
|
||||
job <- JobFactory.fileCopy(args)
|
||||
flag <- queue.insertIfNew(job)
|
||||
_ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F]
|
||||
} yield Option.when(flag)(job)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user