diff --git a/api/src/Api/Worker.hs b/api/src/Api/Worker.hs index 486522f..d701889 100644 --- a/api/src/Api/Worker.hs +++ b/api/src/Api/Worker.hs @@ -64,7 +64,7 @@ data WorkerAPI mode = WorkerAPI , trigger :: mode :- "trigger" :> Capture "id" PipelineId :> QueryParam "WORKER_API_KEY" String :> Get '[JSON] NoContent , error :: mode :- "error" :> Capture "id" PipelineId :> - QueryParam "WORKER_API_KEY" String :> ReqBody '[JSON] ErrorBody :> Post '[JSON] NoContent + QueryParam "WORKER_API_KEY" String :> QueryParam "disable" Bool :> ReqBody '[JSON] ErrorBody :> Post '[JSON] NoContent , refresh :: mode :- "auth" :> Capture "service" Service :> "refresh" :> Capture "id" UserId :> QueryParam "WORKER_API_KEY" String :> ReqBody '[JSON] RefreshBody :> Post '[JSON] NoContent } @@ -101,14 +101,14 @@ triggerHandler pId (Just key) = do triggerHandler _ _ = throwError err403 -errorHandler :: PipelineId -> Maybe String -> ErrorBody -> AppM NoContent -errorHandler pId (Just key) (ErrorBody msg) = do +errorHandler :: PipelineId -> Maybe String -> Maybe Bool -> ErrorBody -> AppM NoContent +errorHandler pId (Just key) maybeDisable (ErrorBody msg) = do k <- liftIO $ envAsString "WORKER_API_KEY" "" if k == key then do - errorPipeline' pId msg + errorPipeline' pId msg maybeDisable return NoContent else throwError err403 -errorHandler _ _ _ = throwError err403 +errorHandler _ _ _ _ = throwError err403 refreshHandler :: Service -> UserId -> Maybe String -> RefreshBody -> AppM NoContent refreshHandler service uid (Just key) (RefreshBody at rt ex) = do diff --git a/api/src/Db/Pipeline.hs b/api/src/Db/Pipeline.hs index c2c4553..73a6827 100644 --- a/api/src/Db/Pipeline.hs +++ b/api/src/Db/Pipeline.hs @@ -151,8 +151,8 @@ triggerPipeline pId currTime = , pipelineError = lit Nothing } -errorPipeline :: PipelineId -> Text -> Update Int64 -errorPipeline pId msg = +errorPipeline :: PipelineId -> Text -> Maybe Bool -> Update Int64 +errorPipeline pId msg Nothing = Update { target = pipelineSchema , from = pure () @@ -160,7 +160,20 @@ errorPipeline pId msg = , set = setter , returning = NumberOfRowsAffected } - where - setter = \from row -> row { - pipelineError = lit $ Just msg - } + where + setter = \from row -> row { + pipelineError = lit $ Just msg + } +errorPipeline pId msg (Just enabled) = + Update + { target = pipelineSchema + , from = pure () + , updateWhere = \_ o -> pipelineId o ==. lit pId + , set = setter + , returning = NumberOfRowsAffected + } + where + setter = \from row -> row { + pipelineError = lit $ Just msg + , pipelineEnabled = lit enabled + } diff --git a/api/src/Repository/Pipeline.hs b/api/src/Repository/Pipeline.hs index 6d54ea0..3670a73 100644 --- a/api/src/Repository/Pipeline.hs +++ b/api/src/Repository/Pipeline.hs @@ -31,5 +31,5 @@ triggerPipeline' pId = do currTime <- liftIO getCurrentTime runQuery $ update $ triggerPipeline pId currTime -errorPipeline' :: PipelineId -> Text -> AppM Int64 -errorPipeline' pId msg = runQuery $ update $ errorPipeline pId msg \ No newline at end of file +errorPipeline' :: PipelineId -> Text -> Maybe Bool ->AppM Int64 +errorPipeline' pId msg mDisable = runQuery $ update $ errorPipeline pId msg (fmap not mDisable) \ No newline at end of file