Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definitions
- Notification = collections.namedtuple('Notification', 'id body publish_date effective_date revised_dat')
- NotificationWithPublishData = collections.namedtuple('NotificationWithPublishData', 'notification is_published')
- # Entities
- def unpublished_notifications(notifications_with_publish_data):
- """Given a list of notification, publish data tuples, return the list of notifications to publish."""
- return [notification_with_publish_data for notification_with_publish_data in notifications_with_publish_data
- if notifications_with_publish_data]
- # Gateways
- NotificationGateway
- DbGateway
- PublishGateway
- # Use cases
- def publish_new_notifications(context, date_range):
- """Given a date range, publish all non-published notifications from context.notification_gateway to
- context.wire_gateway. Set all notifications that are published to `published` on context.db_gateway.
- """
- notifications_in_range = context.notification_gateway.fetch_notifications(date_range)
- notifications_with_published_data = context.db_gateway.fetch_notifications_with_publish_data(notifications_in_range)
- notifications_to_publish = unpublished_notifications(notifications_with_published_data)
- published_notifications = context.publish_gateway.publish(notifications_to_publish)
- context.db_gateway.set_notifications_published(published_notifications)
- # Delivery
- notification_gateway = NotificationGateway('host', 'port')
- db_gateway = DbGateway('host', 'port')
- publish_gateway = PublishGateway()
- context = (notification_gateway, db_gateway, publish_gateway)
- while True:
- publish_new_notifications(context,
- date_range)
- time.sleep(15)
Add Comment
Please, Sign In to add comment