2021-11-11 15:18:04 +01:00
|
|
|
import logging.config
|
2021-05-20 01:57:40 +02:00
|
|
|
|
2021-08-16 10:49:52 +02:00
|
|
|
from mobilizon_reshare.event.event_selection_strategies import select_event_to_publish
|
2022-02-09 00:54:56 +01:00
|
|
|
from mobilizon_reshare.mobilizon.events import get_mobilizon_future_events
|
2021-08-27 23:45:24 +02:00
|
|
|
from mobilizon_reshare.publishers.coordinator import (
|
|
|
|
PublicationFailureNotifiersCoordinator,
|
|
|
|
)
|
2021-08-16 10:49:52 +02:00
|
|
|
from mobilizon_reshare.publishers.coordinator import PublisherCoordinator
|
2021-11-24 23:58:06 +01:00
|
|
|
from mobilizon_reshare.storage.query.read import (
|
|
|
|
get_published_events,
|
|
|
|
build_publications,
|
2021-11-11 15:18:04 +01:00
|
|
|
)
|
2021-11-24 23:58:06 +01:00
|
|
|
from mobilizon_reshare.storage.query.write import (
|
2021-08-05 00:29:50 +02:00
|
|
|
create_unpublished_events,
|
|
|
|
save_publication_report,
|
|
|
|
)
|
2021-05-13 13:32:44 +02:00
|
|
|
|
2021-05-20 01:57:40 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2021-05-13 13:32:44 +02:00
|
|
|
|
2021-10-25 13:43:38 +02:00
|
|
|
async def start():
|
2021-11-11 15:18:04 +01:00
|
|
|
"""
|
|
|
|
STUB
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
2022-02-09 00:54:56 +01:00
|
|
|
# Pull future events from Mobilizon
|
|
|
|
future_events = get_mobilizon_future_events()
|
2021-07-12 22:17:49 +02:00
|
|
|
# Store in the DB only the ones we didn't know about
|
2022-02-09 00:54:56 +01:00
|
|
|
events_without_publications = await create_unpublished_events(future_events)
|
2021-08-05 00:29:50 +02:00
|
|
|
event = select_event_to_publish(
|
2022-02-09 00:54:56 +01:00
|
|
|
list(await get_published_events()),
|
2021-08-05 00:29:50 +02:00
|
|
|
# We must load unpublished events from DB since it contains
|
|
|
|
# merged state between Mobilizon and previous WAITING events.
|
2022-02-09 00:54:56 +01:00
|
|
|
events_without_publications,
|
2021-08-05 00:29:50 +02:00
|
|
|
)
|
2021-08-27 23:45:24 +02:00
|
|
|
|
2021-07-12 22:17:49 +02:00
|
|
|
if event:
|
2021-11-20 15:53:38 +01:00
|
|
|
logger.info(f"Event to publish found: {event.name}")
|
2021-08-27 23:45:24 +02:00
|
|
|
|
2021-11-24 23:58:06 +01:00
|
|
|
publications = await build_publications(event)
|
2021-11-11 15:18:04 +01:00
|
|
|
reports = PublisherCoordinator(publications).run()
|
2021-10-02 18:09:03 +02:00
|
|
|
|
2021-11-24 23:58:06 +01:00
|
|
|
await save_publication_report(reports)
|
2021-10-16 01:25:45 +02:00
|
|
|
for report in reports.reports:
|
2021-11-11 15:18:04 +01:00
|
|
|
if not report.succesful:
|
2022-02-09 00:54:56 +01:00
|
|
|
PublicationFailureNotifiersCoordinator(
|
|
|
|
report,
|
|
|
|
).notify_failure()
|
2021-11-11 15:18:04 +01:00
|
|
|
else:
|
2021-11-20 15:53:38 +01:00
|
|
|
logger.info("No event to publish found")
|