示例#1
0
  def test_create_event_update_message(self):
    service_id = 'facebook'
    service_user_id = 'service_user_id'
    service_event_id = 'service_event_id'
    message = messages.create_event_update_message(service_id, service_user_id, service_event_id)

    self.assertEqual(message['header']['type'], service_id + '.update')
    self.assertEqual(message['message']['service_author_id'], service_user_id)
    self.assertEqual(message['message']['service_event_id'], service_event_id)
示例#2
0
def _send_update_message_from_event(message_client, exchange, event):
  current_id = ""
  if event is not None:
    message = messages.create_event_update_message(
      event.service_name,
      event.service_user_id,
      event.service_event_id)
    message_queue.send_messages(message_client, exchange, [message])
    current_id = event.hash_id

  return current_id
  def app_main(self, config, options, args):
    logging.info("Beginning...")

    db.configure_session(url=db.create_url_from_config(config['db']))

    # 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

    # if authors option is empty default to all authors
    if not options.authors:
      author_names = [author_name for author_name in db.Session().query(Author.author_name).all()]
    else:
      author_names = options.authors

    # get the broker and queue config
    broker_url = config['broker']['url']

    # 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'])

      # for each specified author
      for author_name in author_names:

        # post a update message for service & author
        for asm, event in db.Session().query(AuthorServiceMap, ServiceEvent). \
                                       join(ServiceEvent, and_(AuthorServiceMap.author_id == ServiceEvent.author_id,
                                                               AuthorServiceMap.service_id == ServiceEvent.service_id)). \
                                       join(Service, AuthorServiceMap.service_id == Service.id). \
                                       join(Author, AuthorServiceMap.author_id == Author.id). \
                                       filter(and_(Service.service_name == service_name,
                                                   Author.author_name == author_name)).all():

          if event.type_id == 2:
            continue

          message_queue.send_messages(client,
                                      [create_event_update_message(service_name,
                                                                   asm.service_author_id,
                                                                   event.event_id)])

    logging.info("Finished...")