Ejemplo n.º 1
0
 def notify_event_collector(self, asm):
   notification = messages.create_notification_message('twitter', asm.service_author_id)
   routing_key = notification['header']['type']
   body = json_serializer.dump_string(notification)
   self.amqp.send_message(
       exchange=self.amqp_exchange,
       routing_key=routing_key,
       msg=body)
Ejemplo n.º 2
0
  def test_create_notification_message(self):
    services = ['facebook', 'twitter', 'instagram', 'foursquare', 'linkedin']
    service_user_id = 'service_user_id'

    for service in services:
      message = messages.create_notification_message(service, service_user_id)

      self.assertEqual(message['header']['type'], service + '.notification')
      self.assertEqual(message['message']['service_author_id'], service_user_id)
Ejemplo n.º 3
0
  def app_main(self, config, options, args):
    logging.info("Beginning...")

    # read the db url from the config
    db_url = db.create_url_from_config(config['db'])

    # initialize the db engine & session
    db.configure_session(db_url)

    # if services option is empty default to all available configured services
    if not options.services:
      service_names = []
      # generate the list of service name's from queue list
      for key in config['queues'].iterkeys():
        service_names.append(key)
    else:
      service_names = options.services

    # get the broker and queue config
    broker_url = message_queue.create_url_from_config(config['amqp']['broker'])

    # get message broker client and store in instance
    client = message_queue.create_message_client(broker_url)

    # for each specified service
    for service_name in service_names:

      # create the queue for this service
      message_queue.create_queues_from_config(client, config['amqp'])

      # post a notification for each author subscribed to this service
      for asm in db.Session().query(AuthorServiceMap). \
                              join(Service, AuthorServiceMap.service_id == Service.id). \
                              filter(Service.service_name == service_name).all():
        message_queue.send_messages(client,
                                    [create_notification_message(service_name,
                                                                 asm.service_author_id)])

    logging.info("Finished...")
Ejemplo n.º 4
0
 def convert(notification):
   return create_notification_message('facebook', notification['uid'])