@@ -245,6 +245,7 @@ fetchAgents = do
245245processTicketSafe :: TicketId -> App ()
246246processTicketSafe tId = catch (void $ processTicket tId)
247247 -- Print and log any exceptions related to process ticket
248+ -- TODO(ks): Remove IO from here, return the error.
248249 (\ (e :: ProcessTicketExceptions ) -> do
249250 printText <- asksIOLayer iolPrintText
250251 printText $ show e
@@ -256,6 +257,10 @@ processTicketSafe tId = catch (void $ processTicket tId)
256257processTicket :: TicketId -> App ZendeskResponse
257258processTicket tId = do
258259
260+ -- We first fetch the function from the configuration
261+ printText <- asksIOLayer iolPrintText
262+ appendF <- asksIOLayer iolAppendFile -- We need to remove this.
263+
259264 -- We see 3 HTTP calls here.
260265 getTicketInfo <- asksDataLayer zlGetTicketInfo
261266 getTicketComments <- asksDataLayer zlGetTicketComments
@@ -272,6 +277,16 @@ processTicket tId = do
272277
273278 postTicketComment ticketInfo zendeskResponse
274279
280+ -- TODO(ks): Moved back so we can run it in single-threaded mode. Requires a lot of
281+ -- refactoring to run it in a multi-threaded mode.
282+ let ticketId = getTicketId $ zrTicketId zendeskResponse
283+ -- Append ticket result.
284+ let tags = getTicketTags $ zrTags zendeskResponse
285+ forM_ tags $ \ tag -> do
286+ let formattedTicketIdAndTag = show ticketId <> " " <> tag
287+ printText formattedTicketIdAndTag
288+ appendF " logs/analysis-result.log" (formattedTicketIdAndTag <> " \n " )
289+
275290 pure zendeskResponse
276291
277292-- | When we want to process all tickets from a specific time onwards.
@@ -334,7 +349,9 @@ fetchTickets = do
334349 sortedUnassignedTicketIds <- listAndSortUnassignedTickets
335350
336351 let allTickets = sortedTicketIds <> sortedUnassignedTicketIds
337- return allTickets
352+
353+ -- Anything that has a "to_be_analysed" tag
354+ pure $ filter (elem (renderTicketStatus ToBeAnalyzed ) . getTicketTags . tiTags) allTickets
338355
339356fetchAndShowTickets :: App ()
340357fetchAndShowTickets = do
@@ -477,8 +494,8 @@ inspectAttachments ticketInfo attachments = do
477494 config <- ask
478495 getAttachment <- asksDataLayer zlGetAttachment
479496
480- lastAttach <- handleMaybe . safeHead . reverse . sort $ attachments
481- att <- handleMaybe =<< getAttachment lastAttach
497+ lastAttach <- handleMaybe . safeHead . reverse . sort $ attachments
498+ att <- handleMaybe =<< getAttachment lastAttach
482499 inspectAttachment config ticketInfo att
483500 where
484501 handleMaybe :: Maybe a -> App a
0 commit comments