mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Move user task to scheduler module
This commit is contained in:
parent
83d3644b39
commit
69765f05ff
modules
backend/src/main/scala/docspell/backend
joex/src/main/scala/docspell/joex
restserver/src/main/scala/docspell/restserver/routes
scheduler/api/src/main/scala/docspell/scheduler/usertask
store/src/main/scala/docspell/store/records
@ -15,8 +15,8 @@ import docspell.ftsclient.FtsClient
|
||||
import docspell.notification.api.{EventExchange, NotificationModule}
|
||||
import docspell.pubsub.api.PubSubT
|
||||
import docspell.scheduler.msg.JobQueuePublish
|
||||
import docspell.scheduler.usertask.UserTaskStore
|
||||
import docspell.store.Store
|
||||
import docspell.store.usertask.UserTaskStore
|
||||
import docspell.totp.Totp
|
||||
import emil.Emil
|
||||
|
||||
|
@ -16,10 +16,10 @@ import docspell.common._
|
||||
import docspell.store.UpdateResult
|
||||
import docspell.store.queries.{QCollective, QUser}
|
||||
import docspell.store.records._
|
||||
import docspell.store.usertask.{UserTask, UserTaskScope, UserTaskStore}
|
||||
import docspell.store.{AddResult, Store}
|
||||
import com.github.eikek.calev._
|
||||
import docspell.scheduler.JobQueue
|
||||
import docspell.scheduler.usertask.{UserTask, UserTaskScope, UserTaskStore}
|
||||
|
||||
trait OCollective[F[_]] {
|
||||
|
||||
|
@ -13,9 +13,9 @@ import fs2.Stream
|
||||
import docspell.common._
|
||||
import docspell.notification.api.{ChannelRef, PeriodicDueItemsArgs, PeriodicQueryArgs}
|
||||
import docspell.scheduler.JobQueue
|
||||
import docspell.scheduler.usertask.{UserTask, UserTaskScope, UserTaskStore}
|
||||
import docspell.store.Store
|
||||
import docspell.store.records.RNotificationChannel
|
||||
import docspell.store.usertask._
|
||||
import io.circe.Encoder
|
||||
|
||||
trait OUserTask[F[_]] {
|
||||
|
@ -41,10 +41,9 @@ import docspell.notification.api.NotificationModule
|
||||
import docspell.notification.impl.NotificationModuleImpl
|
||||
import docspell.pubsub.api.{PubSub, PubSubT}
|
||||
import docspell.scheduler.msg.JobQueuePublish
|
||||
import docspell.scheduler.usertask.{UserTaskScope, UserTaskStore}
|
||||
import docspell.store.Store
|
||||
import docspell.store.records.{REmptyTrashSetting, RJobLog}
|
||||
import docspell.store.usertask.UserTaskScope
|
||||
import docspell.store.usertask.UserTaskStore
|
||||
import emil.javamail._
|
||||
import org.http4s.client.Client
|
||||
|
||||
|
@ -9,14 +9,12 @@ package docspell.joex.emptytrash
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.backend.ops.{OItem, OItemSearch}
|
||||
import docspell.common._
|
||||
import docspell.scheduler._
|
||||
import docspell.store.records.RItem
|
||||
import docspell.store.usertask.UserTask
|
||||
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import docspell.scheduler.usertask.UserTask
|
||||
|
||||
object EmptyTrashTask {
|
||||
type Args = EmptyTrashArgs
|
||||
|
@ -8,16 +8,14 @@ package docspell.joex.hk
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.backend.ops.OFileRepository
|
||||
import docspell.common._
|
||||
import docspell.joex.Config
|
||||
import docspell.joex.filecopy.FileIntegrityCheckTask
|
||||
import docspell.scheduler.{JobTaskResultEncoder, Task}
|
||||
import docspell.store.records._
|
||||
import docspell.store.usertask.UserTaskScope
|
||||
|
||||
import com.github.eikek.calev._
|
||||
import docspell.scheduler.usertask.{QUserTask, UserTaskScope}
|
||||
import io.circe.Encoder
|
||||
import io.circe.generic.semiauto.deriveEncoder
|
||||
|
||||
@ -48,7 +46,7 @@ object HouseKeepingTask {
|
||||
Task.log[F, Unit](_.warn("Cancelling house-keeping task"))
|
||||
|
||||
def periodicTask[F[_]: Sync](ce: CalEvent): F[RPeriodicTask] =
|
||||
RPeriodicTask
|
||||
QUserTask
|
||||
.createJson(
|
||||
true,
|
||||
UserTaskScope(DocspellSystem.taskGroup),
|
||||
|
@ -9,15 +9,12 @@ package docspell.joex.updatecheck
|
||||
import cats.data.OptionT
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
import docspell.scheduler.Context
|
||||
import docspell.scheduler.Task
|
||||
import docspell.scheduler.usertask.{UserTask, UserTaskScope}
|
||||
import docspell.store.records.RPeriodicTask
|
||||
import docspell.store.records.RUserEmail
|
||||
import docspell.store.usertask.UserTask
|
||||
import docspell.store.usertask.UserTaskScope
|
||||
|
||||
import emil._
|
||||
|
||||
object UpdateCheckTask {
|
||||
|
@ -9,7 +9,6 @@ package docspell.restserver.routes
|
||||
import cats.data.OptionT
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.backend.BackendApp
|
||||
import docspell.backend.MailAddressCodec
|
||||
import docspell.backend.auth.AuthToken
|
||||
@ -19,8 +18,7 @@ import docspell.restapi.model._
|
||||
import docspell.restserver.Config
|
||||
import docspell.restserver.conv.{Conversions, NonEmptyListSupport}
|
||||
import docspell.restserver.http4s.ClientRequestInfo
|
||||
import docspell.store.usertask._
|
||||
|
||||
import docspell.scheduler.usertask._
|
||||
import org.http4s._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.circe.CirceEntityEncoder._
|
||||
|
@ -9,7 +9,6 @@ package docspell.restserver.routes
|
||||
import cats.data.{NonEmptyList, OptionT}
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.backend.BackendApp
|
||||
import docspell.backend.MailAddressCodec
|
||||
import docspell.backend.auth.AuthToken
|
||||
@ -20,8 +19,7 @@ import docspell.restapi.model._
|
||||
import docspell.restserver.Config
|
||||
import docspell.restserver.conv.{Conversions, NonEmptyListSupport}
|
||||
import docspell.restserver.http4s.ClientRequestInfo
|
||||
import docspell.store.usertask._
|
||||
|
||||
import docspell.scheduler.usertask._
|
||||
import org.http4s._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.circe.CirceEntityEncoder._
|
||||
|
@ -9,14 +9,12 @@ package docspell.restserver.routes
|
||||
import cats.data.OptionT
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.backend.BackendApp
|
||||
import docspell.backend.auth.AuthToken
|
||||
import docspell.common._
|
||||
import docspell.restapi.model._
|
||||
import docspell.restserver.conv.Conversions
|
||||
import docspell.store.usertask._
|
||||
|
||||
import docspell.scheduler.usertask._
|
||||
import org.http4s._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
import org.http4s.circe.CirceEntityEncoder._
|
||||
|
@ -1,20 +1,15 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.queries
|
||||
|
||||
import fs2._
|
||||
package docspell.scheduler.usertask
|
||||
|
||||
import cats.implicits._
|
||||
import cats.effect.Sync
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import docspell.common._
|
||||
import docspell.store.qb.DML
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
import docspell.store.records._
|
||||
import docspell.store.usertask.{UserTask, UserTaskScope}
|
||||
|
||||
import doobie._
|
||||
import docspell.store.records.RPeriodicTask
|
||||
import doobie.ConnectionIO
|
||||
import fs2.Stream
|
||||
import io.circe.Encoder
|
||||
|
||||
object QUserTask {
|
||||
private val RT = RPeriodicTask.T
|
||||
@ -101,4 +96,64 @@ object QUserTask {
|
||||
def makeUserTask(r: RPeriodicTask): UserTask[String] =
|
||||
UserTask(r.id, r.task, r.enabled, r.timer, r.summary, r.args)
|
||||
|
||||
def create[F[_]: Sync](
|
||||
enabled: Boolean,
|
||||
scope: UserTaskScope,
|
||||
task: Ident,
|
||||
args: String,
|
||||
subject: String,
|
||||
priority: Priority,
|
||||
timer: CalEvent,
|
||||
summary: Option[String]
|
||||
): F[RPeriodicTask] =
|
||||
Ident
|
||||
.randomId[F]
|
||||
.flatMap(id =>
|
||||
Timestamp
|
||||
.current[F]
|
||||
.map { now =>
|
||||
RPeriodicTask(
|
||||
id,
|
||||
enabled,
|
||||
task,
|
||||
scope.collective,
|
||||
args,
|
||||
subject,
|
||||
scope.fold(_.user, identity),
|
||||
priority,
|
||||
None,
|
||||
None,
|
||||
timer,
|
||||
timer
|
||||
.nextElapse(now.atZone(Timestamp.UTC))
|
||||
.map(_.toInstant)
|
||||
.map(Timestamp.apply)
|
||||
.getOrElse(Timestamp.Epoch),
|
||||
now,
|
||||
summary
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
def createJson[F[_]: Sync, A](
|
||||
enabled: Boolean,
|
||||
scope: UserTaskScope,
|
||||
task: Ident,
|
||||
args: A,
|
||||
subject: String,
|
||||
priority: Priority,
|
||||
timer: CalEvent,
|
||||
summary: Option[String]
|
||||
)(implicit E: Encoder[A]): F[RPeriodicTask] =
|
||||
create[F](
|
||||
enabled,
|
||||
scope,
|
||||
task,
|
||||
E(args).noSpaces,
|
||||
subject,
|
||||
priority,
|
||||
timer,
|
||||
summary
|
||||
)
|
||||
|
||||
}
|
@ -4,18 +4,15 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.usertask
|
||||
package docspell.scheduler.usertask
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
import docspell.store.records.RPeriodicTask
|
||||
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import io.circe.Decoder
|
||||
import io.circe.Encoder
|
||||
import io.circe.{Decoder, Encoder}
|
||||
|
||||
case class UserTask[A](
|
||||
id: Ident,
|
||||
@ -51,7 +48,7 @@ object UserTask {
|
||||
scope: UserTaskScope,
|
||||
subject: Option[String]
|
||||
): F[RPeriodicTask] =
|
||||
RPeriodicTask
|
||||
QUserTask
|
||||
.create[F](
|
||||
ut.enabled,
|
||||
scope,
|
@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.usertask
|
||||
package docspell.scheduler.usertask
|
||||
|
||||
import docspell.common._
|
||||
|
@ -4,17 +4,14 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.usertask
|
||||
package docspell.scheduler.usertask
|
||||
|
||||
import cats.data.OptionT
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.queries.QUserTask
|
||||
import docspell.store.{AddResult, Store}
|
||||
|
||||
import fs2.Stream
|
||||
import io.circe._
|
||||
|
||||
/** User tasks are `RPeriodicTask`s that can be managed by the user. The user can change
|
@ -9,16 +9,12 @@ package docspell.store.records
|
||||
import cats.data.NonEmptyList
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
import docspell.store.usertask.UserTaskScope
|
||||
|
||||
import com.github.eikek.calev.CalEvent
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import io.circe.Encoder
|
||||
|
||||
/** A periodic task is a special job description, that shares a few properties of a
|
||||
* `RJob`. It must provide all information to create a `RJob` value eventually.
|
||||
@ -65,66 +61,6 @@ case class RPeriodicTask(
|
||||
|
||||
object RPeriodicTask {
|
||||
|
||||
def create[F[_]: Sync](
|
||||
enabled: Boolean,
|
||||
scope: UserTaskScope,
|
||||
task: Ident,
|
||||
args: String,
|
||||
subject: String,
|
||||
priority: Priority,
|
||||
timer: CalEvent,
|
||||
summary: Option[String]
|
||||
): F[RPeriodicTask] =
|
||||
Ident
|
||||
.randomId[F]
|
||||
.flatMap(id =>
|
||||
Timestamp
|
||||
.current[F]
|
||||
.map { now =>
|
||||
RPeriodicTask(
|
||||
id,
|
||||
enabled,
|
||||
task,
|
||||
scope.collective,
|
||||
args,
|
||||
subject,
|
||||
scope.fold(_.user, identity),
|
||||
priority,
|
||||
None,
|
||||
None,
|
||||
timer,
|
||||
timer
|
||||
.nextElapse(now.atZone(Timestamp.UTC))
|
||||
.map(_.toInstant)
|
||||
.map(Timestamp.apply)
|
||||
.getOrElse(Timestamp.Epoch),
|
||||
now,
|
||||
summary
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
def createJson[F[_]: Sync, A](
|
||||
enabled: Boolean,
|
||||
scope: UserTaskScope,
|
||||
task: Ident,
|
||||
args: A,
|
||||
subject: String,
|
||||
priority: Priority,
|
||||
timer: CalEvent,
|
||||
summary: Option[String]
|
||||
)(implicit E: Encoder[A]): F[RPeriodicTask] =
|
||||
create[F](
|
||||
enabled,
|
||||
scope,
|
||||
task,
|
||||
E(args).noSpaces,
|
||||
subject,
|
||||
priority,
|
||||
timer,
|
||||
summary
|
||||
)
|
||||
|
||||
final case class Table(alias: Option[String]) extends TableDef {
|
||||
val tableName = "periodic_task"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user