module IHP.Job.Types
( Job (..)
, JobWorkerArgs (..)
, JobWorker (..)
, JobStatus (..)
, Worker (..)
)
where

import IHP.Prelude
import IHP.FrameworkConfig
import qualified Control.Concurrent.Async as Async

class Job job where
    perform :: (?modelContext :: ModelContext, ?context :: FrameworkConfig) => job -> IO ()

    maxAttempts :: (?job :: job) => Int
    maxAttempts = Int
10

class Worker application where
    workers :: application -> [JobWorker]

data JobWorkerArgs = JobWorkerArgs
    { JobWorkerArgs -> IORef [Async ()]
allJobs :: IORef [Async.Async ()]
    , JobWorkerArgs -> UUID
workerId :: UUID
    , JobWorkerArgs -> ModelContext
modelContext :: ModelContext 
    , JobWorkerArgs -> FrameworkConfig
frameworkConfig :: FrameworkConfig }

newtype JobWorker = JobWorker (JobWorkerArgs -> IO (Async.Async ()))

-- | Mapping for @JOB_STATUS@. The DDL statement for this can be found in IHPSchema.sql:
--
-- > CREATE TYPE JOB_STATUS AS ENUM ('job_status_not_started', 'job_status_running', 'job_status_failed', 'job_status_succeeded', 'job_status_retry');
data JobStatus
    = JobStatusNotStarted
    | JobStatusRunning
    | JobStatusFailed
    | JobStatusSucceeded
    | JobStatusRetry
    deriving (JobStatus -> JobStatus -> Bool
(JobStatus -> JobStatus -> Bool)
-> (JobStatus -> JobStatus -> Bool) -> Eq JobStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JobStatus -> JobStatus -> Bool
$c/= :: JobStatus -> JobStatus -> Bool
== :: JobStatus -> JobStatus -> Bool
$c== :: JobStatus -> JobStatus -> Bool
Eq, Int -> JobStatus -> ShowS
[JobStatus] -> ShowS
JobStatus -> String
(Int -> JobStatus -> ShowS)
-> (JobStatus -> String)
-> ([JobStatus] -> ShowS)
-> Show JobStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JobStatus] -> ShowS
$cshowList :: [JobStatus] -> ShowS
show :: JobStatus -> String
$cshow :: JobStatus -> String
showsPrec :: Int -> JobStatus -> ShowS
$cshowsPrec :: Int -> JobStatus -> ShowS
Show, ReadPrec [JobStatus]
ReadPrec JobStatus
Int -> ReadS JobStatus
ReadS [JobStatus]
(Int -> ReadS JobStatus)
-> ReadS [JobStatus]
-> ReadPrec JobStatus
-> ReadPrec [JobStatus]
-> Read JobStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JobStatus]
$creadListPrec :: ReadPrec [JobStatus]
readPrec :: ReadPrec JobStatus
$creadPrec :: ReadPrec JobStatus
readList :: ReadS [JobStatus]
$creadList :: ReadS [JobStatus]
readsPrec :: Int -> ReadS JobStatus
$creadsPrec :: Int -> ReadS JobStatus
Read, Int -> JobStatus
JobStatus -> Int
JobStatus -> [JobStatus]
JobStatus -> JobStatus
JobStatus -> JobStatus -> [JobStatus]
JobStatus -> JobStatus -> JobStatus -> [JobStatus]
(JobStatus -> JobStatus)
-> (JobStatus -> JobStatus)
-> (Int -> JobStatus)
-> (JobStatus -> Int)
-> (JobStatus -> [JobStatus])
-> (JobStatus -> JobStatus -> [JobStatus])
-> (JobStatus -> JobStatus -> [JobStatus])
-> (JobStatus -> JobStatus -> JobStatus -> [JobStatus])
-> Enum JobStatus
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: JobStatus -> JobStatus -> JobStatus -> [JobStatus]
$cenumFromThenTo :: JobStatus -> JobStatus -> JobStatus -> [JobStatus]
enumFromTo :: JobStatus -> JobStatus -> [JobStatus]
$cenumFromTo :: JobStatus -> JobStatus -> [JobStatus]
enumFromThen :: JobStatus -> JobStatus -> [JobStatus]
$cenumFromThen :: JobStatus -> JobStatus -> [JobStatus]
enumFrom :: JobStatus -> [JobStatus]
$cenumFrom :: JobStatus -> [JobStatus]
fromEnum :: JobStatus -> Int
$cfromEnum :: JobStatus -> Int
toEnum :: Int -> JobStatus
$ctoEnum :: Int -> JobStatus
pred :: JobStatus -> JobStatus
$cpred :: JobStatus -> JobStatus
succ :: JobStatus -> JobStatus
$csucc :: JobStatus -> JobStatus
Enum)