简体   繁体   English

如何在 GCP 云任务中获取任务计数

[英]How to get task count in GCP cloud task

Is there any standard way to get cloud task count for a queue?是否有任何标准方法来获取队列的云任务计数?

I know we can loop through nextPageToken and achieve this.我知道我们可以遍历nextPageToken并实现这一点。

Can this be achieved with single request?这可以通过单个请求来实现吗?

By looking at the documentation, QueueStats seems to be the standard way to get task count.通过查看文档, QueueStats似乎是获取任务计数的标准方法。

As mentioned in @Sameer comment, cloudtask v2beta3 has a feature to request for stats of a queue:正如@Sameer 评论中提到的, cloudtask v2beta3具有请求队列统计信息的功能:

public long geQueueDepth(String queuePath) {
        long depth=-1;

       try {
           FieldMask.Builder fieldBuilder = FieldMask.newBuilder();
           fieldBuilder.addPaths("stats");
           com.google.cloud.tasks.v2beta3.GetQueueRequest queueRequest =
                   com.google.cloud.tasks.v2beta3.GetQueueRequest.newBuilder().setName(queuePath).setReadMask(fieldBuilder).build();;
           com.google.cloud.tasks.v2beta3.Queue queue = cloudTasksClientV3.getQueue(queueRequest);
           depth=queue.getStats().getTasksCount();
          
       }catch (Exception e){
           LOGGER.error("Error while getting queue depth =>{}",e.getMessage());
       }
        return depth;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM