Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amarillo/services/agencyconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self):

# Default: if no role was defined, the default role is
# carpool_agency.
if agency_conf.roles is None:
if agency_conf.roles is None or len(agency_conf.roles) == 0:
agency_conf.roles = [AgencyRole.carpool_agency]

agency_id = agency_conf.agency_id
Expand Down
10 changes: 7 additions & 3 deletions amarillo/services/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def __init__(self, store, agencyconf_service):
self.agencyconf_service = agencyconf_service

def perform_full_sync(self) -> None:
agencies = self.agencyconf_service.get_all_agencies()
for agency in [agency for agency in agencies if self.should_sync(agency)]:
agencies_to_sync = [agency for agency in self.agencyconf_service.get_all_agencies() if self.should_sync(agency)]
logger.info(f"Perform full sync for agencies {agencies_to_sync}")
for agency in agencies_to_sync:
try:
asyncio.run(self.sync(agency.agency_id, agency.offers_download_url, agency.offers_download_http_headers))
except Exception as e:
Expand Down Expand Up @@ -57,9 +58,12 @@ async def sync(self, agency_id: str, offers_download_url=None, offers_download_h
importer = AmarilloImporter(agency_id, offers_download_url, offers_download_http_headers)

sync_start_time = time.time()
logger.info(f"Start sync for agency {agency_id} at {sync_start_time}")

carpools = importer.load_carpools()

result = [await self.store.store_carpool(cp) for cp in carpools]

logger.info(f"Synced {len(result)} offers for agency {agency_id}")

await self.store.delete_agency_carpools_older_than(agency_id, sync_start_time)
return result