Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-pgmq
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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-pgmq
Commits
fcb7d4fb
Verified
Commit
fcb7d4fb
authored
Aug 20, 2024
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add queueAvailableLength to count number of readily available messages
parent
f827b577
Pipeline
#6508
passed with stages
in 8 minutes and 10 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
Simple.hs
src/Database/PGMQ/Simple.hs
+14
-1
Simple.hs
tests/Test/Integration/PGMQ/Simple.hs
+18
-0
No files found.
src/Database/PGMQ/Simple.hs
View file @
fcb7d4fb
...
@@ -32,7 +32,8 @@ module Database.PGMQ.Simple
...
@@ -32,7 +32,8 @@ module Database.PGMQ.Simple
,
readMessagesWithPoll
,
readMessagesWithPoll
,
sendMessage
,
sendMessage
,
sendMessages
,
sendMessages
,
setMessageVt
)
,
setMessageVt
,
queueAvailableLength
)
where
where
...
@@ -254,6 +255,18 @@ setMessageVt conn queue msgId vt =
...
@@ -254,6 +255,18 @@ setMessageVt conn queue msgId vt =
-- | This function returns the number of readily available messages.
-- 'metrics' returns total queue size, but even then, when vt of
-- these messages is set in the future, the read operation might
-- return nothing (see queueAvailableNow).
queueAvailableLength
::
PSQL
.
Connection
->
Queue
->
IO
Int
queueAvailableLength
conn
queue
=
do
let
queueTable
=
"q_"
<>
queue
let
tableId
=
PSQL
.
QualifiedIdentifier
(
Just
"pgmq"
)
$
T
.
pack
queueTable
[
PSQL
.
Only
len
]
<-
PSQL
.
query
conn
[
sql
|
SELECT COUNT(*) FROM ? WHERE vt <= now()
|]
(
PSQL
.
Only
tableId
)
::
IO
[
PSQL
.
Only
Int
]
return
len
{-|
{-|
A utility function: sometimes pgmq throws an error that a table (for
A utility function: sometimes pgmq throws an error that a table (for
queue) doesn't exist and we want to ignore it as it's not critical in
queue) doesn't exist and we want to ignore it as it's not critical in
...
...
tests/Test/Integration/PGMQ/Simple.hs
View file @
fcb7d4fb
...
@@ -118,3 +118,21 @@ pgmqSimpleTests = parallel $ around withPGMQ $ describe "PGMQ Simple" $ do
...
@@ -118,3 +118,21 @@ pgmqSimpleTests = parallel $ around withPGMQ $ describe "PGMQ Simple" $ do
msg1
`
shouldBe
`
message1
msg1
`
shouldBe
`
message1
msg2
`
shouldBe
`
message2
msg2
`
shouldBe
`
message2
)
iter
)
iter
it
"can count messages properly, including vt (https://github.com/tembo-io/pgmq/issues/301)"
$
\
(
TestEnv
{
conn
,
queue
})
->
do
let
message
=
"hello vt test"
::
String
msgId
<-
PGMQ
.
sendMessage
conn
queue
message
1
-- immediately after creating such message, we should get metrics.length = 1 and available length = 0
mMetrics
<-
PGMQ
.
getMetrics
conn
queue
let
mQLen
=
PGMQ
.
queueLength
<$>
mMetrics
mQLen
`
shouldBe
`
(
Just
1
)
aLen
<-
PGMQ
.
queueAvailableLength
conn
queue
aLen
`
shouldBe
`
0
-- Now reset the vt
PGMQ
.
setMessageVt
conn
queue
msgId
0
mMetrics'
<-
PGMQ
.
getMetrics
conn
queue
let
mQLen'
=
PGMQ
.
queueLength
<$>
mMetrics'
mQLen'
`
shouldBe
`
(
Just
1
)
aLen'
<-
PGMQ
.
queueAvailableLength
conn
queue
aLen'
`
shouldBe
`
1
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