Skip to content

Commit 9406daa

Browse files
authored
[TSD-87] Run the debugger on specific tag. (#40)
1 parent 53ef851 commit 9406daa

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/DataSource/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ asksDBLayer getter = do
165165
Config{..} <- ask
166166
pure $ getter cfgDBLayer
167167

168-
169168
-- TODO(ks): Move these three below to CLI!
170169
-- | Path to knowledgebase
171170
knowledgebasePath :: FilePath
@@ -446,6 +445,7 @@ data TicketTag
446445
| AnalyzedByScriptV1_0 -- ^ Ticket has been analyzed by the version 1.0
447446
| AnalyzedByScriptV1_1 -- ^ Ticket has been analyzed by the version 1.1
448447
| AnalyzedByScriptV1_2 -- ^ Ticket has been analyzed by the version 1.2
448+
| ToBeAnalyzed -- ^ Ticket needs to be analyzed
449449
| NoKnownIssue -- ^ Ticket had no known issue
450450
| NoLogAttached -- ^ Log file not attached
451451

@@ -847,5 +847,6 @@ renderTicketStatus AnalyzedByScript = "analyzed-by-script"
847847
renderTicketStatus AnalyzedByScriptV1_0 = "analyzed-by-script-v1.0"
848848
renderTicketStatus AnalyzedByScriptV1_1 = "analyzed-by-script-v1.1"
849849
renderTicketStatus AnalyzedByScriptV1_2 = "analyzed-by-script-v1.2"
850+
renderTicketStatus ToBeAnalyzed = "to_be_analysed" -- https://iohk.zendesk.com/agent/admin/tags
850851
renderTicketStatus NoKnownIssue = "no-known-issues"
851852
renderTicketStatus NoLogAttached = "no-log-files"

src/Lib.hs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ fetchAgents = do
245245
processTicketSafe :: TicketId -> App ()
246246
processTicketSafe 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)
256257
processTicket :: TicketId -> App ZendeskResponse
257258
processTicket 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

339356
fetchAndShowTickets :: App ()
340357
fetchAndShowTickets = 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

Comments
 (0)