This commit is contained in:
iko 2020-05-08 23:39:47 +03:00
parent a65e54644a
commit 991579de10
3 changed files with 52 additions and 1 deletions

View File

@ -41,6 +41,7 @@ scheduleTaskQuery task = do
:* Set (param @2) `as` #payload
:* Default `as` #creation_time
:* Default `as` #started
:* Default `as` #failures
)
( OnConflict
(OnConstraint #pk_task_payload)
@ -87,6 +88,7 @@ rescheduleTaskQuery payload = do
#tasks
( Default `as` #creation_time
:* Default `as` #started
:* Set (#failures + 1) `as` #failures
)
(param @1 .== #task .&& param @2 .== #payload)
dbWrite (const $ return ()) $
@ -112,6 +114,7 @@ pickTasksQuery tasks limitCount = do
( from (table #tasks)
& where_ (#task `in_` (literal <$> tasks))
& where_ (not_ . notNull $ #started)
& where_ (#failures .< 20)
& orderBy [#creation_time & Asc]
& limit limitCount
& orderBy [#creation_time & Desc]

View File

@ -6,13 +6,15 @@ module Server.Schema
where
import Server.Schema.V1
import Server.Schema.V2
import Squeal.PostgreSQL
type StaticPQ m = MonadPQ Schema m
type Schema = SchemaV1
type Schema = SchemaV2
migration :: AlignedList (Migration (Terminally PQ IO)) (Public '[]) Schema
migration =
pureMigration schemaMigrationV1
:>> pureMigration schemaMigrationV2
:>> Done

46
src/Server/Schema/V2.hs Normal file
View File

@ -0,0 +1,46 @@
module Server.Schema.V2
( SchemaV2,
schemaMigrationV2,
)
where
import Data.Aeson
import Data.Int
import Data.Submission
import Data.Text (Text)
import Data.Time
import Server.Schema.V1
import Squeal.PostgreSQL
type SchemaV2 =
Public
'[ "tasks"
::: 'Table
( '[ "pk_task_payload" :=> 'PrimaryKey '["task", "payload"]
]
:=> '[ "task" ::: 'NoDef :=> 'NotNull (PG Text),
"payload" ::: 'NoDef :=> 'NotNull (PG (Jsonb Value)),
"creation_time" ::: 'Def :=> 'NotNull (PG UTCTime),
"started" ::: 'Def :=> 'NotNull (PG Bool),
"failures" ::: 'Def :=> 'NotNull (PG Int32)
]
),
"submissions"
::: 'Table
( '["pk_submission_repo_full_name_sha" :=> 'PrimaryKey '["repo_full_name", "sha"]]
:=> '[ "user_name" ::: 'NoDef :=> 'NotNull (PG String),
"repo_full_name" ::: 'NoDef :=> 'NotNull (PG String),
"problem" ::: 'NoDef :=> 'NotNull (PG String),
"sha" ::: 'NoDef :=> 'NotNull (PG String),
"status" ::: 'NoDef :=> 'NotNull (PG (Jsonb SubmissionStatus))
]
)
]
schemaMigrationV2 :: Migration Definition SchemaV1 SchemaV2
schemaMigrationV2 =
Migration
{ name = "v2",
up = alterTable #tasks (addColumn #failures (default_ 0 $ notNullable int)),
down = alterTable #tasks (dropColumn #failures)
}