Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-bee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-bee
Commits
9c8987f5
Verified
Commit
9c8987f5
authored
Aug 21, 2024
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[worker] simplify exception catching
parent
29113f05
Pipeline
#6510
failed with stages
in 8 minutes and 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
Worker.hs
src/Async/Worker.hs
+27
-27
No files found.
src/Async/Worker.hs
View file @
9c8987f5
...
...
@@ -39,7 +39,7 @@ import Async.Worker.Broker
import
Async.Worker.Types
import
Control.Concurrent.STM
(
atomically
)
import
Control.Concurrent.STM.TVar
(
readTVarIO
,
newTVarIO
,
writeTVar
)
import
Control.Exception.Safe
(
catch
,
fromException
,
throwIO
,
SomeException
,
Exception
)
import
Control.Exception.Safe
(
catch
es
,
Handler
(
..
)
,
throwIO
,
SomeException
,
Exception
)
import
Control.Monad
(
forever
,
void
,
when
)
import
Debug.Trace
(
traceStack
)
import
System.Timeout
qualified
as
Timeout
...
...
@@ -70,40 +70,40 @@ run state@(State { .. }) = do
-- exception handling.
mBrokerMessageTVar
<-
newTVarIO
Nothing
-- :: IO (TVar (Maybe (BrokerMessage b (Job a))))
catch
(
do
catch
es
(
do
brokerMessage
<-
readMessageWaiting
broker
queueName
atomically
$
writeTVar
mBrokerMessageTVar
(
Just
brokerMessage
)
handleMessage
state
brokerMessage
callWorkerJobEvent
onJobFinish
state
brokerMessage
atomically
$
writeTVar
mBrokerMessageTVar
Nothing
)
(
\
err
->
do
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
case
fromException
err
of
Just
KillWorkerSafely
->
do
case
mBrokerMessage
of
Just
brokerMessage
->
do
let
job
=
toA
$
getMessage
brokerMessage
let
mdata
=
metadata
job
-- Should we resend this message?
when
(
resendWhenWorkerKilled
mdata
)
$
do
putStrLn
$
formatStr
state
$
"resending job: "
<>
show
job
void
$
sendJob
broker
queueName
(
job
{
metadata
=
mdata
{
readCount
=
readCount
mdata
+
1
}
})
size
<-
getQueueSize
broker
queueName
putStrLn
$
formatStr
state
$
"queue size: "
<>
show
size
-- In any case, deinit the broker (i.e. close connection)
-- deinitBroker broker
)
[
Handler
$
\
(
_err
::
KillWorkerSafely
)
->
do
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
case
mBrokerMessage
of
Just
brokerMessage
->
do
let
job
=
toA
$
getMessage
brokerMessage
let
mdata
=
metadata
job
-- Should we resend this message?
when
(
resendWhenWorkerKilled
mdata
)
$
do
putStrLn
$
formatStr
state
$
"resending job: "
<>
show
job
void
$
sendJob
broker
queueName
(
job
{
metadata
=
mdata
{
readCount
=
readCount
mdata
+
1
}
})
size
<-
getQueueSize
broker
queueName
putStrLn
$
formatStr
state
$
"queue size: "
<>
show
size
-- kill worker
throwIO
KillWorkerSafely
Nothing
->
pure
()
Nothing
->
case
fromException
err
of
Just
jt
@
(
JobTimeout
{})
->
handleTimeoutError
state
jt
Nothing
->
case
mBrokerMessage
of
-- In any case, deinit the broker (i.e. close connection)
-- deinitBroker broker
-- kill worker
throwIO
KillWorkerSafely
Nothing
->
pure
()
,
Handler
$
\
(
err
::
JobTimeout
b
a
)
->
handleTimeoutError
state
err
,
Handler
$
\
err
->
do
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
case
mBrokerMessage
of
Just
brokerMessage
->
do
callWorkerJobEvent
onJobError
state
brokerMessage
handleJobError
state
brokerMessage
_
->
handleUnknownError
state
err
)
Nothing
->
handleUnknownError
state
err
]
handleMessage
::
(
HasWorkerBroker
b
a
)
=>
State
b
a
->
BrokerMessage
b
(
Job
a
)
->
IO
()
handleMessage
state
@
(
State
{
..
})
brokerMessage
=
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment