Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
151
Issues
151
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
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-gargantext
Commits
f48e7130
Commit
f48e7130
authored
Mar 17, 2025
by
Alfredo Di Napoli
Committed by
Alfredo Di Napoli
Mar 27, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sendTimeout combinator
parent
f0f88f92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
CentralExchange.hs
src/Gargantext/Core/Notifications/CentralExchange.hs
+20
-11
No files found.
src/Gargantext/Core/Notifications/CentralExchange.hs
View file @
f48e7130
...
@@ -31,8 +31,8 @@ import Gargantext.Core.Config (GargConfig, gc_notifications_config, gc_logging)
...
@@ -31,8 +31,8 @@ import Gargantext.Core.Config (GargConfig, gc_notifications_config, gc_logging)
import
Gargantext.Core.Config.Types
(
NotificationsConfig
(
..
))
import
Gargantext.Core.Config.Types
(
NotificationsConfig
(
..
))
import
Gargantext.Core.Notifications.CentralExchange.Types
import
Gargantext.Core.Notifications.CentralExchange.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.System.Logging
(
LogLevel
(
..
),
withLogger
,
logLoc
)
import
Gargantext.System.Logging
(
LogLevel
(
..
),
withLogger
,
logLoc
,
Logger
)
import
Nanomsg
(
Pull
(
..
),
Push
(
..
),
bind
,
connect
,
recv
,
send
,
withSocket
,
shutdown
)
import
Nanomsg
(
Pull
(
..
),
Push
(
..
),
bind
,
connect
,
recv
,
send
,
withSocket
,
shutdown
,
Socket
,
Sender
)
import
System.Timeout
(
timeout
)
import
System.Timeout
(
timeout
)
{-
{-
...
@@ -99,15 +99,29 @@ gServer cfg = do
...
@@ -99,15 +99,29 @@ gServer cfg = do
-- process, independent of the server.
-- process, independent of the server.
-- send the same message that we received
-- send the same message that we received
-- void $ sendNonblocking s_dispatcher r
-- void $ sendNonblocking s_dispatcher r
void
$
timeout
100
_000
$
send
s_dispatcher
r
sendTimeout
ioLogger
s_dispatcher
r
Just
(
UpdateWorkerProgress
_ji
_jl
)
->
do
Just
(
UpdateWorkerProgress
_ji
_jl
)
->
do
-- $(logLoc) ioLogger DEBUG $ "[central_exchange] update worker progress: " <> show ji <> ", " <> show jl
-- $(logLoc) ioLogger DEBUG $ "[central_exchange] update worker progress: " <> show ji <> ", " <> show jl
void
$
timeout
100
_000
$
send
s_dispatcher
r
sendTimeout
ioLogger
s_dispatcher
r
Just
Ping
->
do
Just
Ping
->
do
void
$
timeout
100
_000
$
send
s_dispatcher
r
sendTimeout
ioLogger
s_dispatcher
r
Nothing
->
Nothing
->
$
(
logLoc
)
ioLogger
ERROR
$
"[central_exchange] cannot decode message: "
<>
show
r
$
(
logLoc
)
ioLogger
ERROR
$
"[central_exchange] cannot decode message: "
<>
show
r
-- | A static send timeout in microseconds.
send_timeout_ns
::
Int
send_timeout_ns
=
100
_00
-- | Sends the given payload ensure the send doesn't take more than the static
-- 'send_timeout_ns', logging a message if the timeouts kicks in.
sendTimeout
::
Sender
a
=>
Logger
IO
->
Socket
a
->
ByteString
->
IO
()
sendTimeout
ioLogger
sock
payload
=
withFrozenCallStack
$
do
timeoutKickedIn
<-
timeout
send_timeout_ns
$
send
sock
$
payload
case
timeoutKickedIn
of
Nothing
->
$
(
logLoc
)
ioLogger
ERROR
$
"[central_exchange] couldn't send msg in timely fashion."
Just
()
->
$
(
logLoc
)
ioLogger
DEBUG
$
"[central_exchange] message sent."
notify
::
GargConfig
->
CEMessage
->
IO
()
notify
::
GargConfig
->
CEMessage
->
IO
()
notify
cfg
ceMessage
=
withLogger
log_cfg
$
\
ioLogger
->
do
notify
cfg
ceMessage
=
withLogger
log_cfg
$
\
ioLogger
->
do
...
@@ -120,12 +134,7 @@ notify cfg ceMessage = withLogger log_cfg $ \ioLogger -> do
...
@@ -120,12 +134,7 @@ notify cfg ceMessage = withLogger log_cfg $ \ioLogger -> do
$
(
logLoc
)
ioLogger
DEBUG
$
"[central_exchange] sending: "
<>
(
TE
.
decodeUtf8
$
BSL
.
toStrict
str
)
$
(
logLoc
)
ioLogger
DEBUG
$
"[central_exchange] sending: "
<>
(
TE
.
decodeUtf8
$
BSL
.
toStrict
str
)
-- err <- sendNonblocking s $ BSL.toStrict str
-- err <- sendNonblocking s $ BSL.toStrict str
-- putText $ "[notify] err: " <> show err
-- putText $ "[notify] err: " <> show err
timeoutKickedIn
<-
timeout
100
_000
$
send
s
$
BSL
.
toStrict
str
sendTimeout
ioLogger
s
(
BSL
.
toStrict
str
)
case
timeoutKickedIn
of
Nothing
->
$
(
logLoc
)
ioLogger
ERROR
$
"[central_exchange] couldn't send msg in timely fashion."
Just
()
->
$
(
logLoc
)
ioLogger
DEBUG
$
"[central_exchange] message sent."
do_work
`
finally
`
shutdown
s
connectEndpoint
do_work
`
finally
`
shutdown
s
connectEndpoint
where
where
NotificationsConfig
{
_nc_central_exchange_connect
}
=
cfg
^.
gc_notifications_config
NotificationsConfig
{
_nc_central_exchange_connect
}
=
cfg
^.
gc_notifications_config
...
...
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