Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ale
disque
Commits
e06542e4
Commit
e06542e4
authored
Feb 19, 2016
by
Vojtech Vitek (V-Teq)
Browse files
Implement ActiveLen(), native NACK
parent
7c53cf7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
LICENSE
View file @
e06542e4
MIT License
Copyright (c) 201
4
Pressly Inc. www.pressly.com
Copyright (c) 201
6
Pressly Inc. www.pressly.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
...
...
disque.go
View file @
e06542e4
...
...
@@ -217,19 +217,18 @@ func (pool *Pool) Ack(job *Job) error {
}
// Nack re-queues a job back into its queue.
// Native NACKJOB discussed upstream at https://github.com/antirez/disque/issues/43.
func
(
pool
*
Pool
)
Nack
(
job
*
Job
)
error
{
sess
:=
pool
.
redis
.
Get
()
defer
sess
.
Close
()
if
_
,
err
:=
sess
.
Do
(
"
ENQUEUE
"
,
job
.
ID
);
err
!=
nil
{
if
_
,
err
:=
sess
.
Do
(
"
NACK
"
,
job
.
ID
);
err
!=
nil
{
return
err
}
return
nil
}
// Wait
waits for a job to finish (blocks until it'
s ACKed
)
.
// Native WAITJOB discussed upstream at https://github.com/antirez/disque/issues/
43
.
// Wait
blocks until the given job i
s ACKed.
// Native WAITJOB discussed upstream at https://github.com/antirez/disque/issues/
168
.
func
(
pool
*
Pool
)
Wait
(
job
*
Job
)
error
{
sess
:=
pool
.
redis
.
Get
()
defer
sess
.
Close
()
...
...
@@ -243,7 +242,7 @@ func (pool *Pool) Wait(job *Job) error {
break
}
time
.
Sleep
(
1
0
*
time
.
Millisecond
)
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
}
return
nil
...
...
@@ -261,3 +260,23 @@ func (pool *Pool) Len(queue string) (int, error) {
return
length
,
nil
}
// ActiveLen returns length of active jobs taken from a given queue.
func
(
pool
*
Pool
)
ActiveLen
(
queue
string
)
(
int
,
error
)
{
sess
:=
pool
.
redis
.
Get
()
defer
sess
.
Close
()
reply
,
err
:=
sess
.
Do
(
"JSCAN"
,
"QUEUE"
,
queue
,
"STATE"
,
"active"
)
if
err
!=
nil
{
return
0
,
err
}
replyArr
,
ok
:=
reply
.
([]
interface
{})
if
!
ok
||
len
(
replyArr
)
!=
2
{
return
0
,
errors
.
New
(
"unexpected reply #1"
)
}
jobs
,
ok
:=
replyArr
[
1
]
.
([]
interface
{})
if
!
ok
{
return
0
,
errors
.
New
(
"unexpected reply #2"
)
}
return
len
(
jobs
),
nil
}
Write
Preview
Supports
Markdown
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