Monitoring the status of a google pub/sub submitted job

旧城冷巷雨未停 提交于 2019-12-11 12:54:31

问题


I am new to Google Compute/Google App Engine platform. I am currently migrating a python flask application using celery for async tasks to Google Compute/Google App Engine platform. However in the docs it's written I should use Google Pub/Sub instead of celery. In my application whenever I run an async task I have a page to monitor the status of the job using the same principle as http://blog.miguelgrinberg.com/post/using-celery-with-flask. I have checked the documents for google pub/sub, but I am at loss how to implement the same using google pub/sub. Can anybody help or point me to the right direction to implement the same in google pub/sub.


回答1:


You might be able to use psq for this, which is designed to look like celery. From a general Cloud Pub/Sub perspective, you would follow these steps:

  1. Create a topic for your status update messages.
  2. In the async task whose status you want to monitor, periodically publish a message with the status. This message will be of some format of your choosing that would indicate percentage completion or specific message to display.
  3. Create a subscription for your monitoring page that will receive messages on the topic.
  4. In your monitoring page (or a background process that will supply the data to your monitoring page), pull messages for the subscription.
  5. Process the messages and update the state of your jobs for your monitoring page.
  6. Ack the messages you pulled and processed.

A couple of things to keep in mind in this workflow:

  1. Cloud Pub/Sub guarantees at-least-once delivery. That means you could potentially receive the same message more than once.
  2. Cloud Pub/Sub does not provide any guarantees on ordering. Therefore, if you are periodically publishing status updates, your subscriber could potentially receive these out of order. For your case, you'll probably want your message to include some sort of timestamp or strictly-increasing identifier in your message to sequence your status updates per task. If you keep track of the most recent status update received, then you can disregard older messages and ack them immediately.


来源:https://stackoverflow.com/questions/37070442/monitoring-the-status-of-a-google-pub-sub-submitted-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!