Client for Cloud Scheduler API#
-
class
google.cloud.scheduler_v1beta1.
CloudSchedulerClient
(transport=None, channel=None, credentials=None, client_config=None, client_info=None, client_options=None)[source]# The Cloud Scheduler API allows external entities to reliably schedule asynchronous jobs.
Constructor.
- Parameters
(Union[CloudSchedulerGrpcTransport, (transport) – Callable[[~.Credentials, type], ~.CloudSchedulerGrpcTransport]): A transport instance, responsible for actually making the API calls. The default transport uses the gRPC protocol. This argument may also be a callable which returns a transport instance. Callables will be sent the credentials as the first argument and the default transport class as the second argument.
channel (grpc.Channel) – DEPRECATED. A
Channel
instance through which to make calls. This argument is mutually exclusive withcredentials
; providing both will raise an exception.credentials (google.auth.credentials.Credentials) – The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to
transport
; doing so will raise an exception.client_config (dict) – DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.
client_info (google.api_core.gapic_v1.client_info.ClientInfo) – The client info used to send a user-agent string along with API requests. If
None
, then default info will be used. Generally, you only need to set this if you’re developing your own client library.client_options (Union[dict, google.api_core.client_options.ClientOptions]) – Client options used to set user options on the client. API Endpoint should be set through client_options.
-
create_job
(parent, job, retry=<object object>, timeout=<object object>, metadata=None)[source]# Creates a job.
Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> parent = client.location_path('[PROJECT]', '[LOCATION]') >>> >>> # TODO: Initialize `job`: >>> job = {} >>> >>> response = client.create_job(parent, job)
- Parameters
parent (str) –
Required.
The location name. For example:
projects/PROJECT_ID/locations/LOCATION_ID
.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.If a dict is provided, it must be of the same form as the protobuf message
Job
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
delete_job
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Deletes a job.
Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') >>> >>> client.delete_job(name)
- Parameters
name (str) –
Required.
The job name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
enums
= <module 'google.cloud.scheduler_v1beta1.gapic.enums' from '/usr/local/lib/python3.7/site-packages/google/cloud/scheduler_v1beta1/gapic/enums.py'>#
-
classmethod
from_service_account_file
(filename, *args, **kwargs)[source]# Creates an instance of this client using the provided credentials file.
- Parameters
filename (str) – The path to the service account private key json file.
args – Additional arguments to pass to the constructor.
kwargs – Additional arguments to pass to the constructor.
- Returns
The constructed client.
- Return type
-
classmethod
from_service_account_json
(filename, *args, **kwargs)# Creates an instance of this client using the provided credentials file.
- Parameters
filename (str) – The path to the service account private key json file.
args – Additional arguments to pass to the constructor.
kwargs – Additional arguments to pass to the constructor.
- Returns
The constructed client.
- Return type
-
get_job
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Gets a job.
Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') >>> >>> response = client.get_job(name)
- Parameters
name (str) –
Required.
The job name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
list_jobs
(parent, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Lists jobs.
Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> parent = client.location_path('[PROJECT]', '[LOCATION]') >>> >>> # Iterate over all results >>> for element in client.list_jobs(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_jobs(parent).pages: ... for element in page: ... # process element ... pass
- Parameters
parent (str) –
Required.
The location name. For example:
projects/PROJECT_ID/locations/LOCATION_ID
.page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
PageIterator
instance. An iterable ofJob
instances. You can also iterate over the pages of the response using its pages property.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
pause_job
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# 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 instate
; if paused it will be set toJob.State.PAUSED
. A job must be inJob.State.ENABLED
to be paused.Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') >>> >>> response = client.pause_job(name)
- Parameters
name (str) –
Required.
The job name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
resume_job
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Resume a job.
This method reenables a job after it has been
Job.State.PAUSED
. The state of a job is stored inJob.state
; after calling this method it will be set toJob.State.ENABLED
. A job must be inJob.State.PAUSED
to be resumed.Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') >>> >>> response = client.resume_job(name)
- Parameters
name (str) –
Required.
The job name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
run_job
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Forces a job to run now.
When this method is called, Cloud Scheduler will dispatch the job, even if the job is already running.
Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') >>> >>> response = client.run_job(name)
- Parameters
name (str) –
Required.
The job name. For example:
projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
update_job
(job, update_mask=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# 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.Example
>>> from google.cloud import scheduler_v1beta1 >>> >>> client = scheduler_v1beta1.CloudSchedulerClient() >>> >>> # TODO: Initialize `job`: >>> job = {} >>> >>> response = client.update_job(job)
- Parameters
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.
If a dict is provided, it must be of the same form as the protobuf message
Job
update_mask (Union[dict, FieldMask]) –
A mask used to specify which fields of the job are being updated.
If a dict is provided, it must be of the same form as the protobuf message
FieldMask
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will be retried using a default configuration.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Job
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.