mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Allow to start a user task once
This commit is contained in:
@ -54,7 +54,7 @@ object BackendApp {
|
||||
jobImpl <- OJob(store, joexImpl)
|
||||
itemImpl <- OItem(store)
|
||||
mailImpl <- OMail(store, JavaMailEmil(blocker))
|
||||
userTaskImpl <- OUserTask(utStore, joexImpl)
|
||||
userTaskImpl <- OUserTask(utStore, queue, joexImpl)
|
||||
} yield new BackendApp[F] {
|
||||
val login: Login[F] = loginImpl
|
||||
val signup: OSignup[F] = signupImpl
|
||||
|
@ -2,26 +2,54 @@ package docspell.backend.ops
|
||||
|
||||
import cats.implicits._
|
||||
import cats.effect._
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import io.circe.Encoder
|
||||
import docspell.store.queue.JobQueue
|
||||
import docspell.store.usertask._
|
||||
import docspell.common._
|
||||
import com.github.eikek.calev.CalEvent
|
||||
|
||||
trait OUserTask[F[_]] {
|
||||
|
||||
/** Return the settings for the notify-due-items task of the current
|
||||
* user. There is at most one such task per user.
|
||||
*/
|
||||
def getNotifyDueItems(account: AccountId): F[UserTask[NotifyDueItemsArgs]]
|
||||
|
||||
/** Updates the notify-due-items tasks and notifies the joex nodes.
|
||||
*/
|
||||
def submitNotifyDueItems(
|
||||
account: AccountId,
|
||||
task: UserTask[NotifyDueItemsArgs]
|
||||
): F[Unit]
|
||||
|
||||
/** Discards the schedule and immediately submits the task to the job
|
||||
* executor's queue. It will not update the corresponding periodic
|
||||
* task.
|
||||
*/
|
||||
def executeNow[A](account: AccountId, task: UserTask[A])(
|
||||
implicit E: Encoder[A]
|
||||
): F[Unit]
|
||||
}
|
||||
|
||||
object OUserTask {
|
||||
|
||||
def apply[F[_]: Effect](store: UserTaskStore[F], joex: OJoex[F]): Resource[F, OUserTask[F]] =
|
||||
def apply[F[_]: Effect](
|
||||
store: UserTaskStore[F],
|
||||
queue: JobQueue[F],
|
||||
joex: OJoex[F]
|
||||
): Resource[F, OUserTask[F]] =
|
||||
Resource.pure[F, OUserTask[F]](new OUserTask[F] {
|
||||
|
||||
def executeNow[A](account: AccountId, task: UserTask[A])(
|
||||
implicit E: Encoder[A]
|
||||
): F[Unit] =
|
||||
for {
|
||||
ptask <- task.encode.toPeriodicTask(account)
|
||||
job <- ptask.toJob
|
||||
_ <- queue.insert(job)
|
||||
_ <- joex.notifyAllNodes
|
||||
} yield ()
|
||||
|
||||
def getNotifyDueItems(account: AccountId): F[UserTask[NotifyDueItemsArgs]] =
|
||||
store
|
||||
.getOneByName[NotifyDueItemsArgs](account, NotifyDueItemsArgs.taskName)
|
||||
|
Reference in New Issue
Block a user