Skip to content

Commit

Permalink
update_stored_cohorts using load_cohort
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Aug 5, 2024
1 parent 9864e46 commit 7043732
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/amplitude_experiment/cohort/cohort_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ def download_cohort(self, cohort_id: str) -> Cohort:
def update_stored_cohorts(self) -> Future:
def update_task():
errors = []
try:
futures = [self.executor.submit(self.__load_cohort_internal, cohort_id) for cohort_id in self.cohort_storage.get_cohort_ids()]
cohort_ids = self.cohort_storage.get_cohort_ids()

for future, cohort_id in zip(as_completed(futures), self.cohort_storage.get_cohort_ids()):
try:
future.result()
except Exception as e:
errors.append((cohort_id, e))
except Exception as e:
errors.append(e)
futures = []
with self.lock_jobs:
for cohort_id in cohort_ids:
future = self.load_cohort(cohort_id)
futures.append(future)

for future in as_completed(futures):
cohort_id = next(c_id for c_id, f in self.jobs.items() if f == future)
try:
future.result()
except Exception as e:
errors.append((cohort_id, e))

if errors:
raise CohortUpdateException(errors)
Expand Down

0 comments on commit 7043732

Please sign in to comment.