Skip to content

Commit

Permalink
api: add error document type to the add doc endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Dec 20, 2023
1 parent 5237f2a commit 5125006
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 2 deletions.
152 changes: 150 additions & 2 deletions codegen/Monocle/Protob/Crawler.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions doc/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions schemas/monocle/protob/crawler.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ enum EntityType {
ENTITY_TYPE_USER = 3;
}

message CrawlerError {
string message = 1;
string body = 2;
}

message AddDocRequest {
string index = 1;
string crawler = 2;
Expand All @@ -45,6 +50,7 @@ message AddDocRequest {
repeated monocle_issue.Issue issues = 10;
// issue_events are added when Entity is project_issue_name
repeated monocle_issue.IssueEvent issue_events = 11;
repeated CrawlerError errors = 12;
}

enum AddDocError {
Expand Down
5 changes: 5 additions & 0 deletions src/Macroscope/Worker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ data DocumentType
| DTChanges (Change, [ChangeEvent])
| DTTaskData TaskData
| DTIssues (Issue, [IssueEvent])
| DTError CrawlerError
deriving (Generic, ToJSON)

data ProcessError es
Expand Down Expand Up @@ -246,6 +247,7 @@ runStreamError startTime apiKey indexName (CrawlerName crawlerName) documentStre
addDocRequestTaskDatas = V.fromList $ mapMaybe getTD xs
addDocRequestIssues = V.fromList $ mapMaybe getIssue xs
addDocRequestIssueEvents = V.fromList $ concat $ mapMaybe getIssueEvent xs
addDocRequestErrors = V.fromList $ mapMaybe getError xs
in AddDocRequest {..}
where
getIssue = \case
Expand All @@ -266,6 +268,9 @@ runStreamError startTime apiKey indexName (CrawlerName crawlerName) documentStre
getTD = \case
DTTaskData td -> Just td
_ -> Nothing
getError = \case
DTError e -> Just e
_ -> Nothing

-- 'commitTimestamp' post the commit date.
commitTimestamp entity = do
Expand Down
1 change: 1 addition & 0 deletions src/Monocle/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ crawlerAddDoc _auth request = do
taskDatas
issues
issuesEvents
_errors
) = request

let requestE = do
Expand Down

0 comments on commit 5125006

Please sign in to comment.