Exemplo n.º 1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A PullResponse message with the response of the Pull operation.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        pull_req = msgs.PubsubProjectsSubscriptionsPullRequest(
            pullRequest=msgs.PullRequest(maxMessages=args.max_messages,
                                         returnImmediately=True),
            subscription=util.SubscriptionFormat(args.subscription))

        pull_response = pubsub.projects_subscriptions.Pull(pull_req)

        if args.auto_ack and pull_response.receivedMessages:
            ack_ids = [
                message.ackId for message in pull_response.receivedMessages
            ]

            ack_req = msgs.PubsubProjectsSubscriptionsAcknowledgeRequest(
                acknowledgeRequest=msgs.AcknowledgeRequest(ackIds=ack_ids),
                subscription=util.SubscriptionFormat(args.subscription))
            pubsub.projects_subscriptions.Acknowledge(ack_req)

        return pull_response
Exemplo n.º 2
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A 2-tuple of lists, one populated with the subscription paths that were
      successfully created, the other one with the list of subscription names
      that could not be created.
    """
    msgs = self.context['pubsub_msgs']
    pubsub = self.context['pubsub']

    succeeded = []
    failed = []

    for subscription in args.subscription:
      create_req = msgs.Subscription(name=util.SubscriptionFormat(subscription),
                                     topic=util.TopicFormat(
                                         args.topic, args.topic_project),
                                     ackDeadlineSeconds=args.ack_deadline)
      if args.push_endpoint:
        create_req.pushConfig = msgs.PushConfig(pushEndpoint=args.push_endpoint)

      try:
        succeeded.append(pubsub.projects_subscriptions.Create(create_req))
      except api_ex.HttpError as exc:
        failed.append((subscription,
                       json.loads(exc.content)['error']['message']))

    return succeeded, failed
Exemplo n.º 3
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A 2-tuple of lists, one populated with the subscription paths that were
      successfully deleted, the other one with the list of subscription paths
      that could not be deleted.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        succeeded = []
        failed = []

        for subscription_name in args.subscription:
            delete_req = msgs.PubsubProjectsSubscriptionsDeleteRequest(
                subscription=util.SubscriptionFormat(subscription_name))
            try:
                pubsub.projects_subscriptions.Delete(delete_req)
                succeeded.append(delete_req.subscription)
            except api_ex.HttpError as e:
                failed.append((delete_req.subscription,
                               json.loads(e.content)['error']['message']))

        return succeeded, failed
Exemplo n.º 4
0
    def Display(self, args, result):
        """This method is called to print the result of the Run() method.

    Args:
      args: The arguments that command was run with.
      result: The value returned from the Run() method.
    """
        log.out.Print(
            '{0} message(s) acknowledged for subscription {1}'.format(
                len(args.ackid), util.SubscriptionFormat(args.subscription)))
Exemplo n.º 5
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        ack_req = msgs.PubsubProjectsSubscriptionsAcknowledgeRequest(
            acknowledgeRequest=msgs.AcknowledgeRequest(ackIds=args.ackid),
            subscription=util.SubscriptionFormat(args.subscription))

        pubsub.projects_subscriptions.Acknowledge(ack_req)
Exemplo n.º 6
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        mod_req = msgs.PubsubProjectsSubscriptionsModifyPushConfigRequest(
            modifyPushConfigRequest=msgs.ModifyPushConfigRequest(
                pushConfig=msgs.PushConfig(pushEndpoint=args.push_endpoint)),
            subscription=util.SubscriptionFormat(args.subscription))

        pubsub.projects_subscriptions.ModifyPushConfig(mod_req)
Exemplo n.º 7
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        # TODO(b/22324116): Update to V1 API.
        mod_req = msgs.PubsubProjectsSubscriptionsModifyAckDeadlineRequest(
            modifyAckDeadlineRequest=msgs.ModifyAckDeadlineRequest(
                ackDeadlineSeconds=args.ack_deadline, ackId=args.ackid),
            subscription=util.SubscriptionFormat(args.subscription))

        pubsub.projects_subscriptions.ModifyAckDeadline(mod_req)