Skip to content

Commit 9713e21

Browse files
authored
process work items in random order (#540)
for the estimation of the survival rate to be representative, the sample must be random, so execute the tasks in random order see #490 and #491
1 parent aa63d36 commit 9713e21

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/cosmic_ray/work_db.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
from pathlib import Path
66

7-
from sqlalchemy import Column, Enum, ForeignKey, Integer, JSON, String, Text, create_engine, event
7+
from sqlalchemy import Column, Enum, ForeignKey, Integer, JSON, String, Text, create_engine, event, func
88
from sqlalchemy.exc import IntegrityError
99
from sqlalchemy.orm import declarative_base, relationship
1010
from sqlalchemy.orm.session import sessionmaker
@@ -145,7 +145,7 @@ def pending_work_items(self):
145145
"Iterable of all pending work items. In random order."
146146
with self._session_maker.begin() as session:
147147
completed_job_ids = session.query(WorkResultStorage.job_id)
148-
pending = session.query(WorkItemStorage).where(~WorkItemStorage.job_id.in_(completed_job_ids))
148+
pending = session.query(WorkItemStorage).where(~WorkItemStorage.job_id.in_(completed_job_ids)).order_by(func.random())
149149
return tuple(_work_item_from_storage(work_item) for work_item in pending)
150150

151151
@property

0 commit comments

Comments
 (0)