| 1 | # Copyright 2019, Google LLC | ||||||||||
| 2 | # | ||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||
| 6 | # | ||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 8 | # | ||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||
| 13 | # limitations under the License. | ||||||||||
| 14 | # | ||||||||||
| 15 | # This module manages long-running operations with an API service. | ||||||||||
| 16 | |||||||||||
| 17 | package Google::Ads::GoogleAds::LongRunning::OperationService; | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use base qw(Google::Ads::GoogleAds::BaseService); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | use Google::Ads::GoogleAds::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | use Time::HiRes qw(sleep); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | use constant DEFAULT_POLL_FREQUENCY_SECONDS => 5; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | ▶ | use constant DEFAULT_POLL_TIMEOUT_SECONDS => 60; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | # Class::Std-style attributes. Need to be kept in the same line. | ||||||||||
| 31 | # These need to go in the same line for older Perl interpreters to understand. | ||||||||||
| 32 | 2 | my %version_of : ATTR(:name<version> :default<>); | |||||||||
| 33 | |||||||||||
| 34 | # Automatically called by Class::Std after the values for all the attributes | ||||||||||
| 35 | # have been populated but before the constructor returns the new object. | ||||||||||
| 36 | 1 | ▶ | sub START { | ||||||||
|
Subroutine
START: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 1 | my ($self, $ident) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 1 | $version_of{$ident} = | |||||||||
| 40 | lc Google::Ads::GoogleAds::Constants::OPERATION_SERVICE_VERSION; | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | # Gets the latest state of a long-running operation. | ||||||||||
| 44 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my $request_body = shift; | |||||||||
| 47 | 0 | my $http_method = 'GET'; | |||||||||
| 48 | 0 | my $request_path = sprintf '%s/{+name}', $self->get_version(); | |||||||||
| 49 | 0 | my $response_type = 'Google::Ads::GoogleAds::LongRunning::Operation'; | |||||||||
| 50 | |||||||||||
| 51 | 0 | return $self->SUPER::call($http_method, $request_path, $request_body, | |||||||||
| 52 | $response_type); | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # Deletes a long-running operation. | ||||||||||
| 56 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | 0 | my $request_body = shift; | |||||||||
| 59 | 0 | my $http_method = 'DELETE'; | |||||||||
| 60 | 0 | my $request_path = sprintf '%s/{+name}', $self->get_version(); | |||||||||
| 61 | 0 | my $response_type = ''; | |||||||||
| 62 | |||||||||||
| 63 | 0 | return $self->SUPER::call($http_method, $request_path, $request_body, | |||||||||
| 64 | $response_type); | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | # Starts asynchronous cancellation on a long-running operation. | ||||||||||
| 68 | 0 | ▶ | sub cancel { | ||||||||
|
Subroutine
cancel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 0 | my $self = shift; | |||||||||
| 70 | 0 | my $request_body = shift; | |||||||||
| 71 | 0 | my $http_method = 'POST'; | |||||||||
| 72 | 0 | my $request_path = sprintf '%s/{+name}:cancel', $self->get_version(); | |||||||||
| 73 | 0 | my $response_type = ''; | |||||||||
| 74 | |||||||||||
| 75 | 0 | return $self->SUPER::call($http_method, $request_path, $request_body, | |||||||||
| 76 | $response_type); | ||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | # Polls the specified long-running operation until it is done or reaches at most | ||||||||||
| 80 | # a specified timeout. | ||||||||||
| 81 | 0 | ▶ | sub poll_until_done { | ||||||||
|
Subroutine
poll_until_done: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 82 | 0 | my $self = shift; | |||||||||
| 83 | 0 | my $request_body = shift; | |||||||||
| 84 | |||||||||||
| 85 | my $poll_frequency_seconds = | ||||||||||
| 86 | $request_body->{pollFrequencySeconds} | ||||||||||
| 87 | ? $request_body->{pollFrequencySeconds} | ||||||||||
| 88 | 0 | ▶ | : DEFAULT_POLL_FREQUENCY_SECONDS; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | |||||||||||
| 90 | my $poll_timeout_seconds = | ||||||||||
| 91 | $request_body->{pollTimeoutSeconds} | ||||||||||
| 92 | ? $request_body->{pollTimeoutSeconds} | ||||||||||
| 93 | 0 | ▶ | : DEFAULT_POLL_TIMEOUT_SECONDS; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | |||||||||||
| 95 | 0 | my $lro; | |||||||||
| 96 | 0 | my $elapsed_seconds = 0; | |||||||||
| 97 | 0 | ▶ | while ($elapsed_seconds < $poll_timeout_seconds) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | $lro = $self->get({name => $request_body->{name}}); | |||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | last if $lro->{done}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | |||||||||||
| 102 | 0 | sleep($poll_frequency_seconds); | |||||||||
| 103 | 0 | $elapsed_seconds += $poll_frequency_seconds; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 0 | return $lro; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 2 | 1; | |||||||||
| 110 | |||||||||||
| 111 | =pod | ||||||||||
| 112 | |||||||||||
| 113 | =head1 NAME | ||||||||||
| 114 | |||||||||||
| 115 | Google::Ads::GoogleAds::LongRunning::OperationService | ||||||||||
| 116 | |||||||||||
| 117 | =head1 SYNOPSIS | ||||||||||
| 118 | |||||||||||
| 119 | my $operation_service = $api_client->OperationService(); | ||||||||||
| 120 | |||||||||||
| 121 | $operation_service->poll_until_complete({ | ||||||||||
| 122 | name => $lro_name, | ||||||||||
| 123 | pollFrequencySeconds => 5, | ||||||||||
| 124 | pollTimeoutSeconds => 60 | ||||||||||
| 125 | }); | ||||||||||
| 126 | |||||||||||
| 127 | =head1 DESCRIPTION | ||||||||||
| 128 | |||||||||||
| 129 | This module manages long-running operations with an API service. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 METHODS | ||||||||||
| 132 | |||||||||||
| 133 | =head2 get | ||||||||||
| 134 | |||||||||||
| 135 | Gets the latest state of a long-running operation. | ||||||||||
| 136 | |||||||||||
| 137 | =head3 Parameters | ||||||||||
| 138 | |||||||||||
| 139 | =over | ||||||||||
| 140 | |||||||||||
| 141 | =item * | ||||||||||
| 142 | |||||||||||
| 143 | I<request_body>: a L<Google::Ads::GoogleAds::LongRunning::GetOperationRequest> object. | ||||||||||
| 144 | |||||||||||
| 145 | =back | ||||||||||
| 146 | |||||||||||
| 147 | =head2 delete | ||||||||||
| 148 | |||||||||||
| 149 | Deletes a long-running operation. | ||||||||||
| 150 | |||||||||||
| 151 | =head3 Parameters | ||||||||||
| 152 | |||||||||||
| 153 | =over | ||||||||||
| 154 | |||||||||||
| 155 | =item * | ||||||||||
| 156 | |||||||||||
| 157 | I<request_body>: a L<Google::Ads::GoogleAds::LongRunning::DeleteOperationRequest> object. | ||||||||||
| 158 | |||||||||||
| 159 | =back | ||||||||||
| 160 | |||||||||||
| 161 | =head2 cancel | ||||||||||
| 162 | |||||||||||
| 163 | Starts asynchronous cancellation on a long-running operation. | ||||||||||
| 164 | |||||||||||
| 165 | =head3 Parameters | ||||||||||
| 166 | |||||||||||
| 167 | =over | ||||||||||
| 168 | |||||||||||
| 169 | =item * | ||||||||||
| 170 | |||||||||||
| 171 | I<request_body>: a L<Google::Ads::GoogleAds::LongRunning::CancelOperationRequest> object. | ||||||||||
| 172 | |||||||||||
| 173 | =back | ||||||||||
| 174 | |||||||||||
| 175 | =head2 poll_until_done | ||||||||||
| 176 | |||||||||||
| 177 | Polls the specified long-running operation until it is done or reaches at most a | ||||||||||
| 178 | specified timeout. | ||||||||||
| 179 | |||||||||||
| 180 | =head3 Parameters | ||||||||||
| 181 | |||||||||||
| 182 | =over | ||||||||||
| 183 | |||||||||||
| 184 | =item * | ||||||||||
| 185 | |||||||||||
| 186 | I<request_body>: a L<Google::Ads::GoogleAds::LongRunning::PollOperationRequest> object. | ||||||||||
| 187 | |||||||||||
| 188 | =back | ||||||||||
| 189 | |||||||||||
| 190 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 191 | |||||||||||
| 192 | Copyright 2019 Google LLC | ||||||||||
| 193 | |||||||||||
| 194 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 195 | you may not use this file except in compliance with the License. | ||||||||||
| 196 | You may obtain a copy of the License at | ||||||||||
| 197 | |||||||||||
| 198 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 199 | |||||||||||
| 200 | Unless required by applicable law or agreed to in writing, software | ||||||||||
| 201 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 202 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 203 | See the License for the specific language governing permissions and | ||||||||||
| 204 | limitations under the License. | ||||||||||
| 205 | |||||||||||
| 206 | =head1 REPOSITORY INFORMATION | ||||||||||
| 207 | |||||||||||
| 208 | $Rev: $ | ||||||||||
| 209 | $LastChangedBy: $ | ||||||||||
| 210 | $Id: $ | ||||||||||
| 211 | |||||||||||
| 212 | =cut | ||||||||||