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
Show 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
...
@@ -39,7 +39,7 @@ import Async.Worker.Broker
import
Async.Worker.Types
import
Async.Worker.Types
import
Control.Concurrent.STM
(
atomically
)
import
Control.Concurrent.STM
(
atomically
)
import
Control.Concurrent.STM.TVar
(
readTVarIO
,
newTVarIO
,
writeTVar
)
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
Control.Monad
(
forever
,
void
,
when
)
import
Debug.Trace
(
traceStack
)
import
Debug.Trace
(
traceStack
)
import
System.Timeout
qualified
as
Timeout
import
System.Timeout
qualified
as
Timeout
...
@@ -70,16 +70,14 @@ run state@(State { .. }) = do
...
@@ -70,16 +70,14 @@ run state@(State { .. }) = do
-- exception handling.
-- exception handling.
mBrokerMessageTVar
<-
newTVarIO
Nothing
-- :: IO (TVar (Maybe (BrokerMessage b (Job a))))
mBrokerMessageTVar
<-
newTVarIO
Nothing
-- :: IO (TVar (Maybe (BrokerMessage b (Job a))))
catch
(
do
catch
es
(
do
brokerMessage
<-
readMessageWaiting
broker
queueName
brokerMessage
<-
readMessageWaiting
broker
queueName
atomically
$
writeTVar
mBrokerMessageTVar
(
Just
brokerMessage
)
atomically
$
writeTVar
mBrokerMessageTVar
(
Just
brokerMessage
)
handleMessage
state
brokerMessage
handleMessage
state
brokerMessage
callWorkerJobEvent
onJobFinish
state
brokerMessage
callWorkerJobEvent
onJobFinish
state
brokerMessage
atomically
$
writeTVar
mBrokerMessageTVar
Nothing
)
[
)
(
\
err
->
do
Handler
$
\
(
_err
::
KillWorkerSafely
)
->
do
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
case
fromException
err
of
Just
KillWorkerSafely
->
do
case
mBrokerMessage
of
case
mBrokerMessage
of
Just
brokerMessage
->
do
Just
brokerMessage
->
do
let
job
=
toA
$
getMessage
brokerMessage
let
job
=
toA
$
getMessage
brokerMessage
...
@@ -97,13 +95,15 @@ run state@(State { .. }) = do
...
@@ -97,13 +95,15 @@ run state@(State { .. }) = do
-- kill worker
-- kill worker
throwIO
KillWorkerSafely
throwIO
KillWorkerSafely
Nothing
->
pure
()
Nothing
->
pure
()
Nothing
->
case
fromException
err
of
,
Handler
$
\
(
err
::
JobTimeout
b
a
)
->
handleTimeoutError
state
err
Just
jt
@
(
JobTimeout
{})
->
handleTimeoutError
state
jt
,
Handler
$
\
err
->
do
Nothing
->
case
mBrokerMessage
of
mBrokerMessage
<-
readTVarIO
mBrokerMessageTVar
case
mBrokerMessage
of
Just
brokerMessage
->
do
Just
brokerMessage
->
do
callWorkerJobEvent
onJobError
state
brokerMessage
callWorkerJobEvent
onJobError
state
brokerMessage
handleJobError
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
::
(
HasWorkerBroker
b
a
)
=>
State
b
a
->
BrokerMessage
b
(
Job
a
)
->
IO
()
handleMessage
state
@
(
State
{
..
})
brokerMessage
=
do
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