Home > Blockchain >  How to pause and resume a gcp scheduler from a gcp function?
How to pause and resume a gcp scheduler from a gcp function?

Time:07-25

I have been trying to pause a cloud scheduler if a condition is true and this all can be done in a function using Python only. So, is it possible? Please help me

CodePudding user response:

In the documentation you have examples for pausing and resuming jobs.

For Pausing:

from google.cloud import scheduler_v1

def sample_pause_job():
    # Create a client
    client = scheduler_v1.CloudSchedulerClient()

    # Initialize request argument(s)
    request = scheduler_v1.PauseJobRequest(
        name="name_value",
    )

    # Make the request
    response = client.pause_job(request=request)

    # Handle the response
    print(response)

For resuming:

from google.cloud import scheduler_v1

def sample_resume_job():
    # Create a client
    client = scheduler_v1.CloudSchedulerClient()

    # Initialize request argument(s)
    request = scheduler_v1.ResumeJobRequest(
        name="name_value",
    )

    # Make the request
    response = client.resume_job(request=request)

    # Handle the response
    print(response)
  • Related