Google::CloudTasks - Perl client library for the Google CloudTasks API (unofficial).
use Google::CloudTasks; my $client = Google::CloudTasks->client( version => 'v2', credentials_path => '/path/to/credentials.json', ); # Create task my $project_id = 'myproject'; my $location_id = 'asia-northeast1'; my $queue_id = 'myqueue'; my $parent = "projects/$project_id/locations/$location_id/queues/$queue_id"; my $task = { name => "$parent/tasks/mytask-01234567", appEngineHttpRequest => { relativeUri => '/do_task', }, } my $ret = $client->create_task($parent, $task);
Google::CloudTasks https://cloud.google.com/tasks/docs/reference/rest/
This is a Perl client library for the Google CloudTasks API.
A service account with appropriate roles is required. You need to download JSON file and specify credentials_path. See also: https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account
credentials_path
All methods handle raw hashref (or arrayref of hashref), rather than objects.
my $client = Google::CloudTasks->client( version => 'v2', credentials_path => '/path/to/credentials.json', );
version is an API version. (Currently only v2 is available) credentials_path is a path to a service account JSON file.
version
v2
Refer the detailed representation of location at https://cloud.google.com/tasks/docs/reference/rest/Shared.Types/ListLocationsResponse#Location
Gets information about a location.
my $location = $client->get_location("projects/$PROJECT_ID/locations/$LOCATION_ID");
Lists information about all locations under project.
my $ret = $client->list_locations("projects/$PROJECT_ID"); my $locations = $ret->{locations};
Refer the detailed representation of queue at https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues#Queue
Creates a queue.
my $queue = { name => 'queue-name', }; my $created = $client->create_queue("projects/$PROJECT_ID/locations/$LOCATION_ID", $queue);
Deletes a queue.
$client->delete_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID")
Gets information of a queue.
my $queue = $client->get_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID");
Lists information of all queues.
my $ret = $client->list_queues("projects/$PROJECT_ID/locations/$LOCATION_ID"); my $queues = $ret->{queues};
Updates a queue.
my $queue = { retryConfig => { maxAttempts => 5, }, }; my $update_mask = { updateMask => 'retryConfig.maxAttempts' }; my $updated = $client->patch_queue( "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", $queue, $update_mask, # optional );
Pauses a queue.
my $queue = $client->pause_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID");
Resumes a queue.
my $queue = $client->resume_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID");
Gets the access control policy for a queue.
my $policy = $client->get_iam_policy_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID");
Sets the access control policy for a queue.
my $policy = { bindings => [ +{ role => 'roles/viewer', members => [ 'serviceAccount:service-account-name@myproject.gserviceaccount.com', ], } ], etag => $etag, # got via get_iam_policy_queue }; $policy = $client->set_iam_policy_queue( "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", $policy, );
Refer the detailed representation of task at https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks#Task
Creates a task. Note that a request body in appEngineHttpRequest should be base64-encoded.
appEngineHttpRequest
use MIME::Base64; my $body = encode_base64('{"name": "TaskTest"}'); chomp($body); my $task = { name => "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", appEngineHttpRequest => { relativeUri => '/path', headers => [ 'Content-Type' => 'application/json', ], body => $body, }, }; my $created = $client->create_task( "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", $task );
Deletes a task.
$client->delete_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID");
Gets information of a task.
my $task = $client->get_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID");
Lists information of all tasks.
my $ret = $client->list_tasks("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); my $tasks = $ret->{tasks};
Runs a task.
my $ret = $client->run_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID");
The following methods has implemented, but not tested nor documented yet.
Queue.testIamPermissions
Copyright (C) egawata.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
egawata (egawa dot takashi at gmail.com)
To install Google::CloudTasks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Google::CloudTasks
CPAN shell
perl -MCPAN -e shell install Google::CloudTasks
For more information on module installation, please visit the detailed CPAN module installation guide.