2022-01-04 21:35:43 +01:00
|
|
|
import logging
|
2022-03-06 10:41:02 +01:00
|
|
|
from typing import Optional
|
2022-01-04 21:35:43 +01:00
|
|
|
from uuid import UUID
|
|
|
|
|
2022-05-17 23:14:52 +02:00
|
|
|
from mobilizon_reshare.main.publish import publish_publications
|
2022-01-04 21:35:43 +01:00
|
|
|
from mobilizon_reshare.publishers.coordinator import (
|
2022-03-06 10:41:02 +01:00
|
|
|
PublisherCoordinatorReport,
|
2022-01-04 21:35:43 +01:00
|
|
|
)
|
2022-02-09 00:54:56 +01:00
|
|
|
from mobilizon_reshare.storage.query.exceptions import EventNotFound
|
2022-02-14 21:10:27 +01:00
|
|
|
from mobilizon_reshare.storage.query.read import (
|
|
|
|
get_failed_publications_for_event,
|
|
|
|
get_publication,
|
|
|
|
)
|
2022-01-04 21:35:43 +01:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-05-17 23:14:52 +02:00
|
|
|
async def retry_event_publications(event_id) -> Optional[PublisherCoordinatorReport]:
|
2022-01-04 21:35:43 +01:00
|
|
|
|
|
|
|
failed_publications = await get_failed_publications_for_event(event_id)
|
|
|
|
if not failed_publications:
|
|
|
|
logger.info("No failed publications found.")
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info(f"Found {len(failed_publications)} publications.")
|
2022-05-17 23:14:52 +02:00
|
|
|
return await publish_publications(failed_publications)
|
2022-01-04 21:35:43 +01:00
|
|
|
|
|
|
|
|
2022-03-06 10:41:02 +01:00
|
|
|
async def retry_publication(publication_id) -> Optional[PublisherCoordinatorReport]:
|
2022-02-14 21:10:27 +01:00
|
|
|
publication = await get_publication(publication_id)
|
|
|
|
if not publication:
|
|
|
|
logger.info(f"Publication {publication_id} not found.")
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info(f"Publication {publication_id} found.")
|
2022-05-17 23:14:52 +02:00
|
|
|
return await publish_publications([publication])
|
2022-02-14 21:10:27 +01:00
|
|
|
|
|
|
|
|
2022-03-06 10:41:02 +01:00
|
|
|
async def retry_event(
|
|
|
|
mobilizon_event_id: UUID = None,
|
|
|
|
) -> Optional[PublisherCoordinatorReport]:
|
2022-01-04 21:35:43 +01:00
|
|
|
if mobilizon_event_id is None:
|
|
|
|
raise NotImplementedError(
|
|
|
|
"Autonomous retry not implemented yet, please specify an event_id"
|
|
|
|
)
|
|
|
|
try:
|
2022-05-17 23:14:52 +02:00
|
|
|
return await retry_event_publications(mobilizon_event_id)
|
2022-01-04 21:35:43 +01:00
|
|
|
except EventNotFound as e:
|
|
|
|
logger.debug(e, exc_info=True)
|
|
|
|
logger.error(f"Event with id {mobilizon_event_id} not found")
|
|
|
|
return
|