def create_subscription()

in python-batch/batch.py [0:0]


  def create_subscription(self):
    """
    Creates a subscription with name the same as `sub-` + Job.

    Subscription will be ordered and have exactly one time delivery.

    Args:

    Returns:
      None
    """

    self.subscriber = pubsub_v1.SubscriberClient()
    self.subscription_id = "sub-" + self.job_id

    self.topic_path = self.publisher.topic_path(self.project_id, self.job_id)
    self.subscription_path = self.subscriber.subscription_path(self.project_id, self.subscription_id)

    with self.subscriber:
      self.subscription = self.subscriber.create_subscription(
        request={
          "name": self.subscription_path, 
          "topic": self.topic_path,
          "enable_message_ordering": True,
          "enable_exactly_once_delivery": True,
        }
      )
    print(f"Created subscription {self.subscription_path}\n", file=sys.stderr)