Search code examples
google-app-enginegoogle-cloud-platformgoogle-cloud-tasks

How to configure the cloud tasks queue programmatically


Dev thanks for opening this question and I hope so you can help me to get rid out if the situation.

I am new to the Google cloud service and I am learning the cloud task, I have to create the queue programmatically and add some arguments like processing rate, bucket size. i am not able to find any solution till now.

i am creating the queue in the following way

const createQueue = async (
    queueName: string
) => {
    const project = 'projectname'; // Your GCP Project id
    const queue = queueName; // Name of the Queue to create
    const location = 'location name' // The GCP region in which to create the queue
    const {
        v2beta3
    } = require('@google-cloud/tasks');
    const client = new v2beta3.CloudTasksClient();

    try {
        const [response] = await client.createQueue({
            parent: client.locationPath(project, location),
            queue: {
                name: client.queuePath(project, location, queue),
                appEngineHttpQueue: {
                    appEngineRoutingOverride: {
                        service: 'default'
                    }
                },
            },
        });
        console.log(`Created queue ${response.name}`);
        return response.name;
    } catch (error) {
        console.error(Error(error.message));
    }
    // return null
}

how can I add the arguments like processing rate, bucket size, and the max concurrent rate


Solution

  • you need to add this property "rateLimits" to your "queue" property for example

    queue: {
       name:client.queuePath(project,location,queue),
       appEngineHttpQueue:{
          appEngineRoutingOverride:{
             service:default
          },
          rateLimits:{
             maxDispatchesPerSecond:500
          },
          retryConfig:{
             maxAttempts:1
          }
       }
    

    keep in mind that the property "max_burst_size" is equal to "bucket_size"