Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. # Definitions
  2.  
  3. Notification = collections.namedtuple('Notification', 'id body publish_date effective_date revised_dat')
  4. NotificationWithPublishData = collections.namedtuple('NotificationWithPublishData', 'notification is_published')
  5.  
  6. # Entities
  7.  
  8. def unpublished_notifications(notifications_with_publish_data):
  9. """Given a list of notification, publish data tuples, return the list of notifications to publish."""
  10. return [notification_with_publish_data for notification_with_publish_data in notifications_with_publish_data
  11. if notifications_with_publish_data]
  12.  
  13.  
  14. # Gateways
  15. NotificationGateway
  16.  
  17. DbGateway
  18.  
  19. PublishGateway
  20.  
  21. # Use cases
  22.  
  23. def publish_new_notifications(context, date_range):
  24. """Given a date range, publish all non-published notifications from context.notification_gateway to
  25. context.wire_gateway. Set all notifications that are published to `published` on context.db_gateway.
  26. """
  27. notifications_in_range = context.notification_gateway.fetch_notifications(date_range)
  28.  
  29. notifications_with_published_data = context.db_gateway.fetch_notifications_with_publish_data(notifications_in_range)
  30.  
  31. notifications_to_publish = unpublished_notifications(notifications_with_published_data)
  32.  
  33. published_notifications = context.publish_gateway.publish(notifications_to_publish)
  34.  
  35. context.db_gateway.set_notifications_published(published_notifications)
  36.  
  37.  
  38. # Delivery
  39.  
  40. notification_gateway = NotificationGateway('host', 'port')
  41. db_gateway = DbGateway('host', 'port')
  42. publish_gateway = PublishGateway()
  43.  
  44. context = (notification_gateway, db_gateway, publish_gateway)
  45.  
  46. while True:
  47. publish_new_notifications(context,
  48. date_range)
  49. time.sleep(15)
Add Comment
Please, Sign In to add comment