feat: query param to disable

This commit is contained in:
GitBluub
2022-03-05 17:52:04 +01:00
committed by Zoe Roux
parent 6f1d2c743a
commit 7f80a8927a
3 changed files with 26 additions and 13 deletions
+5 -5
View File
@@ -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
+19 -6
View File
@@ -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
}
+2 -2
View File
@@ -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
errorPipeline' :: PipelineId -> Text -> Maybe Bool ->AppM Int64
errorPipeline' pId msg mDisable = runQuery $ update $ errorPipeline pId msg (fmap not mDisable)