You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The algorithm for the completed_count property of the class dramatiq.composition.group returns prematurely.
Checklist
Does your title concisely summarize the problem?
Did you include a minimal, reproducible example?
What OS are you using?
What version of Dramatiq are you using?
What did you do?
What did you expect would happen?
What happened?
What OS are you using?
Archlinux (uname -a gives : Linux Pisces 5.15.2-arch1-1 #1 SMP PREEMPT Fri, 12 Nov 2021 19:22:10 +0000 x86_64 GNU/Linux)
What version of Dramatiq are you using?
dramatiq version 1.12.0
with django-dramatiq version 0.10.0
What did you do?
Create a group of multiple messages, run it, then call completed_count every 0.5 second.
(I configured dramatiq to use Memcached as a result backend and RabbitMQ as a broker in my Django project settings, but this is not relevant for the issue.)
importtimeimportdramatiq@dramatiq.actor(store_results=True)defwait_actor(seconds):
time.sleep(seconds)
return'finished'if__name__=='__main__':
group_messages= []
foriin [1, 4, 1, 1]:
group_messages.append(wait_actor.message(i))
g=dramatiq.group(group_messages).run()
whilenotg.completed:
print(g.completed_count) # will stick on `1` until the second task has finishedtime.sleep(0.5)
print(g.completed_count) # back to 4
What did you expect would happen?
The number of completed tasks shouldn't stick on 1 (but on 3 according to my example).
What happened?
As the second task is slower, and ended after all the others, the number returned by completed_count sticks on 1.
The logs are :
0
0
1
1
1
1
1
4
My guess is that the completed_count property actually returns on the first uncompleted child, and does not check the completeness of the followings.
@propertydefcompleted_count(self):
"""Returns the total number of jobs that have been completed. Actors that don't store results are not counted, meaning this may be inaccurate if all or some of your actors don't store results. Raises: RuntimeError: If your broker doesn't have a result backend set up. Returns: int: The total number of results. """forcount, childinenumerate(self.children, start=1):
try:
ifisinstance(child, group):
child.get_results()
else:
child.get_result()
exceptResultMissing:
returncount-1# <-- This returns without checking the completeness of subsequent children.returncount
To me, a possible solutions would be :
@propertydefcompleted_count(self):
"""Returns the total number of jobs that have been completed. Actors that don't store results are not counted, meaning this may be inaccurate if all or some of your actors don't store results. Raises: RuntimeError: If your broker doesn't have a result backend set up. Returns: int: The total number of results. """count=0forchildinself.children:
try:
ifisinstance(child, group):
child.get_results()
else:
child.get_result()
count+=1exceptResultMissing:
passreturncount
The text was updated successfully, but these errors were encountered:
Issues
The algorithm for the
completed_count
property of the classdramatiq.composition.group
returns prematurely.Checklist
What OS are you using?
Archlinux (
uname -a
gives : Linux Pisces 5.15.2-arch1-1 #1 SMP PREEMPT Fri, 12 Nov 2021 19:22:10 +0000 x86_64 GNU/Linux)What version of Dramatiq are you using?
dramatiq
version1.12.0
with
django-dramatiq
version0.10.0
What did you do?
Create a group of multiple messages, run it, then call
completed_count
every 0.5 second.(I configured dramatiq to use Memcached as a result backend and RabbitMQ as a broker in my Django project settings, but this is not relevant for the issue.)
What did you expect would happen?
The number of completed tasks shouldn't stick on
1
(but on3
according to my example).What happened?
As the second task is slower, and ended after all the others, the number returned by
completed_count
sticks on1
.The logs are :
My guess is that the
completed_count
property actually returns on the first uncompleted child, and does not check the completeness of the followings.To me, a possible solutions would be :
The text was updated successfully, but these errors were encountered: