Skip to content

Instantly share code, notes, and snippets.

@3b

3b/.lisp Secret

Last active September 20, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3b/83fb8e20b14413b320c8213f04fb261f to your computer and use it in GitHub Desktop.
Save 3b/83fb8e20b14413b320c8213f04fb261f to your computer and use it in GitHub Desktop.
(defun parse-logs (stream)
(let ((channel (lparallel:make-channel))
(count 0)
(bad 0))
(loop for line = (read-line stream nil nil)
while line
when (json-line-p line)
do (incf count)
(lparallel:submit-task
channel
(let ((line line))
(lambda ()
(multiple-value-list (ignore-errors (parse-line line)))))))
(loop repeat count
for (result error) = (lparallel:receive-result channel)
if error
do (incf bad)
else if (slowlog-p result)
collect result into slowlogs
else if (grok-fail-p result)
collect result into groklogs
finally (return (values slowlogs groklogs bad)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment