Reference documentation and code samples for the Cloud Scheduler V1beta1 Client class CloudSchedulerClient.
Service Description: The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$cloudSchedulerClient = new CloudSchedulerClient();
try {
$formattedParent = $cloudSchedulerClient->locationName('[PROJECT]', '[LOCATION]');
$job = new Job();
$response = $cloudSchedulerClient->createJob($formattedParent, $job);
} finally {
$cloudSchedulerClient->close();
}
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Methods
jobName
Formats a string containing the fully-qualified path to represent a job resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
job |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted job resource. |
locationName
Formats a string containing the fully-qualified path to represent a location resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted location resource. |
topicName
Formats a string containing the fully-qualified path to represent a topic resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
topic |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted topic resource. |
parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- job: projects/{project}/locations/{location}/jobs/{job}
- location: projects/{project}/locations/{location}
- topic: projects/{project}/topics/{topic}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
Parameters | |
---|---|
Name | Description |
formattedName |
string
The formatted name string |
template |
string
Optional name of template to match |
Returns | |
---|---|
Type | Description |
array | An associative array from name component IDs to component values. |
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
createJob
Creates a job.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The location name. For example:
|
job |
Google\Cloud\Scheduler\V1beta1\Job
Required. The job to add. The user can optionally specify a name for the job in name. name cannot be the same as an existing job. If a name is not specified then the system will generate a random unique name that will be returned (name) in the response. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedParent The location name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID`. Please see
* {@see CloudSchedulerClient::locationName()} for help formatting this field.
*/
function create_job_sample(string $formattedParent): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Prepare any non-scalar elements to be passed along with the request.
$job = new Job();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->createJob($formattedParent, $job);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudSchedulerClient::locationName('[PROJECT]', '[LOCATION]');
create_job_sample($formattedParent);
}
deleteJob
Deletes a job.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The job name. For example:
|
optionalArgs |
array
Optional. |
↳ legacyAppEngineCron |
bool
This field is used to manage the legacy App Engine Cron jobs using the Cloud Scheduler API. If the field is set to true, the job in the __cron queue with the corresponding name will be deleted instead. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
/**
* @param string $formattedName The job name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Please see
* {@see CloudSchedulerClient::jobName()} for help formatting this field.
*/
function delete_job_sample(string $formattedName): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
$cloudSchedulerClient->deleteJob($formattedName);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudSchedulerClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');
delete_job_sample($formattedName);
}
getJob
Gets a job.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The job name. For example:
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedName The job name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Please see
* {@see CloudSchedulerClient::jobName()} for help formatting this field.
*/
function get_job_sample(string $formattedName): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->getJob($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudSchedulerClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');
get_job_sample($formattedName);
}
listJobs
Lists jobs.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The location name. For example:
|
optionalArgs |
array
Optional. |
↳ filter |
string
|
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ legacyAppEngineCron |
bool
This field is used to manage the legacy App Engine Cron jobs using the Cloud Scheduler API. If the field is set to true, the jobs in the __cron queue will be listed instead. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedParent The location name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID`. Please see
* {@see CloudSchedulerClient::locationName()} for help formatting this field.
*/
function list_jobs_sample(string $formattedParent): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudSchedulerClient->listJobs($formattedParent);
/** @var Job $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = CloudSchedulerClient::locationName('[PROJECT]', '[LOCATION]');
list_jobs_sample($formattedParent);
}
pauseJob
Pauses a job.
If a job is paused then the system will stop executing the job until it is re-enabled via ResumeJob. The state of the job is stored in state; if paused it will be set to Job.State.PAUSED. A job must be in Job.State.ENABLED to be paused.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The job name. For example:
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedName The job name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Please see
* {@see CloudSchedulerClient::jobName()} for help formatting this field.
*/
function pause_job_sample(string $formattedName): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->pauseJob($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudSchedulerClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');
pause_job_sample($formattedName);
}
resumeJob
Resume a job.
This method reenables a job after it has been Job.State.PAUSED. The state of a job is stored in Job.state; after calling this method it will be set to Job.State.ENABLED. A job must be in Job.State.PAUSED to be resumed.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The job name. For example:
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedName The job name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Please see
* {@see CloudSchedulerClient::jobName()} for help formatting this field.
*/
function resume_job_sample(string $formattedName): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->resumeJob($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudSchedulerClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');
resume_job_sample($formattedName);
}
runJob
Forces a job to run now.
When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The job name. For example:
|
optionalArgs |
array
Optional. |
↳ legacyAppEngineCron |
bool
This field is used to manage the legacy App Engine Cron jobs using the Cloud Scheduler API. If the field is set to true, the job in the __cron queue with the corresponding name will be forced to run instead. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* @param string $formattedName The job name. For example:
* `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. Please see
* {@see CloudSchedulerClient::jobName()} for help formatting this field.
*/
function run_job_sample(string $formattedName): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->runJob($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudSchedulerClient::jobName('[PROJECT]', '[LOCATION]', '[JOB]');
run_job_sample($formattedName);
}
updateJob
Updates a job.
If successful, the updated Job is
returned. If the job does not exist, NOT_FOUND
is returned.
If UpdateJob does not successfully return, it is possible for the job to be in an Job.State.UPDATE_FAILED state. A job in this state may not be executed. If this happens, retry the UpdateJob request until a successful response is received.
Parameters | |
---|---|
Name | Description |
job |
Google\Cloud\Scheduler\V1beta1\Job
Required. The new job properties. name must be specified. Output only fields cannot be modified using UpdateJob. Any value specified for an output only field will be ignored. |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
A mask used to specify which fields of the job are being updated. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Scheduler\V1beta1\Job |
use Google\ApiCore\ApiException;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1beta1\Job;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_job_sample(): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Prepare any non-scalar elements to be passed along with the request.
$job = new Job();
// Call the API and handle any network failures.
try {
/** @var Job $response */
$response = $cloudSchedulerClient->updateJob($job);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
getLocation
Gets information about a location.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
Resource name for the location. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Location\Location |
use Google\ApiCore\ApiException;
use Google\Cloud\Location\Location;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function get_location_sample(): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $cloudSchedulerClient->getLocation();
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
listLocations
Lists information about the supported locations for this service.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
The resource that owns the locations collection, if applicable. |
↳ filter |
string
The standard list filter. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\Location;
use Google\Cloud\Scheduler\V1beta1\CloudSchedulerClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function list_locations_sample(): void
{
// Create a client.
$cloudSchedulerClient = new CloudSchedulerClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudSchedulerClient->listLocations();
/** @var Location $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
Constants
SERVICE_NAME
Value: 'google.cloud.scheduler.v1beta1.CloudScheduler'
The name of the service.
SERVICE_ADDRESS
Value: 'cloudscheduler.googleapis.com'
The default address of the service.
DEFAULT_SERVICE_PORT
Value: 443
The default port of the service.
CODEGEN_NAME
Value: 'gapic'
The name of the code generator, to be included in the agent header.