-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up async tasks to new AnnotationProject.status field (#5350)
Hook up async tasks to new AnnotationProject.status field update changelog add .env.local to gitignore Co-authored-by: James Santucci <james.santucci@gmail.com>
- Loading branch information
Showing
12 changed files
with
239 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ metals.sbt | |
|
||
/.env | ||
/.envrc | ||
.env.local | ||
|
||
.node_modules | ||
dist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
app-backend/datamodel/src/main/scala/AnnotationProjectStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.rasterfoundry.datamodel | ||
|
||
import cats.implicits._ | ||
import io.circe._ | ||
import io.circe.syntax._ | ||
|
||
import scala.util.Try | ||
|
||
abstract class AnnotationProjectStatus(val repr: String) | ||
|
||
abstract class ProgressStage(val stage: String) | ||
extends AnnotationProjectStatus(stage) | ||
abstract class ErrorStage(val stage: String) | ||
extends AnnotationProjectStatus(stage) | ||
|
||
object ErrorStage { | ||
val fromString = new PartialFunction[String, ErrorStage] { | ||
def apply(s: String) = s.toUpperCase match { | ||
case "TASK_GRID_FAILURE" => AnnotationProjectStatus.TaskGridFailure | ||
case "IMAGE_INGESTION_FAILURE" => | ||
AnnotationProjectStatus.ImageIngestionFailure | ||
case "UNKNOWN_FAILURE" => AnnotationProjectStatus.UnknownFailure | ||
} | ||
def isDefinedAt(s: String): Boolean = | ||
Set("TASK_GRID_FAILURE", "IMAGE_INGESTION_FAILURE", "UNKNOWN_FAILURE") | ||
.contains(s.toUpperCase) | ||
} | ||
|
||
} | ||
|
||
object ProgressStage { | ||
val fromString = new PartialFunction[String, ProgressStage] { | ||
def apply(s: String) = s.toUpperCase match { | ||
case "WAITING" => AnnotationProjectStatus.Waiting | ||
case "QUEUED" => AnnotationProjectStatus.Queued | ||
case "PROCESSING" => AnnotationProjectStatus.Processing | ||
case "READY" => AnnotationProjectStatus.Ready | ||
} | ||
def isDefinedAt(s: String): Boolean = | ||
Set("WAITING", "QUEUED", "PROCESSING", "READY").contains(s.toUpperCase) | ||
} | ||
} | ||
|
||
object AnnotationProjectStatus { | ||
case object Waiting extends ProgressStage("WAITING") | ||
case object Queued extends ProgressStage("QUEUED") | ||
case object Processing extends ProgressStage("PROCESSING") | ||
case object Ready extends ProgressStage("READY") | ||
|
||
case object TaskGridFailure extends ErrorStage("TASK_GRID_FAILURE") | ||
case object ImageIngestionFailure | ||
extends ErrorStage("IMAGE_INGESTION_FAILURE") | ||
case object UnknownFailure extends ErrorStage("UNKNOWN_FAILURE") | ||
|
||
implicit val decoderErrorStatus: Decoder[ErrorStage] = | ||
Decoder.forProduct1("errorStage")( | ||
(stage: String) => ErrorStage.fromString(stage) | ||
) | ||
implicit val encoderErrorStatus: Encoder[ErrorStage] = | ||
Encoder.forProduct1("errorStage")( | ||
(stage: ErrorStage) => stage.repr | ||
) | ||
implicit val decoderProgressStatus: Decoder[ProgressStage] = | ||
Decoder.decodeString.emapTry( | ||
(status: String) => Try { ProgressStage.fromString(status) } | ||
) | ||
implicit val encoderProgressStatus: Encoder[ProgressStage] = | ||
Encoder.forProduct1("status")( | ||
(status: ProgressStage) => status.repr | ||
) | ||
|
||
def fromString: PartialFunction[String, AnnotationProjectStatus] = | ||
ErrorStage.fromString.orElse(ProgressStage.fromString) | ||
|
||
implicit def encAnnProjStat: Encoder[AnnotationProjectStatus] = | ||
new Encoder[AnnotationProjectStatus] { | ||
def apply(thing: AnnotationProjectStatus): Json = thing match { | ||
case ps: ProgressStage => Map("status" -> ps.repr).asJson | ||
case es: ErrorStage => Map("errorStage" -> es.repr).asJson | ||
} | ||
} | ||
|
||
implicit def decAnnProjStat: Decoder[AnnotationProjectStatus] = | ||
Decoder[ProgressStage].widen or Decoder[ErrorStage].widen | ||
} |
23 changes: 23 additions & 0 deletions
23
app-backend/db/src/main/resources/migrations/V36__annotation_project_status.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TYPE public.annotation_project_status AS ENUM ( | ||
'WAITING', | ||
'QUEUED', | ||
'PROCESSING', | ||
'READY', | ||
'UNKNOWN_FAILURE', | ||
'TASK_GRID_FAILURE', | ||
'IMAGE_INGESTION_FAILURE' | ||
); | ||
|
||
ALTER TABLE public.annotation_projects | ||
ADD COLUMN status public.annotation_project_status; | ||
|
||
-- set default values and add null constraint | ||
ALTER TABLE public.annotation_projects ADD CONSTRAINT annotation_project_status_not_null CHECK (status IS NOT NULL) NOT VALID; | ||
|
||
UPDATE public.annotation_projects SET status = 'READY' WHERE ready = true; | ||
UPDATE public.annotation_projects SET status = 'UNKNOWN_FAILURE' WHERE ready = false; | ||
|
||
ALTER TABLE public.annotation_projects VALIDATE CONSTRAINT annotation_project_status_not_null; | ||
|
||
-- drop old column | ||
ALTER TABLE annotation_projects DROP COLUMN ready; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.