0
0
GCPcloud~10 mins

Cloud Tasks for async processing in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Cloud Tasks client.

GCP
from google.cloud import tasks_v2

client = tasks_v2.CloudTasksClient([1])
Drag options to blanks, or click blank then click option'
Aproject='my-project'
Bqueue='my-queue'
Clocation='us-central1'
Dclient_options=None
Attempts:
3 left
💡 Hint
Common Mistakes
Passing project or location directly to the client constructor causes errors.
Trying to pass queue name in client constructor is invalid.
2fill in blank
medium

Complete the code to build the fully qualified queue path.

GCP
parent = client.queue_path('[1]', 'us-central1', 'my-queue')
Drag options to blanks, or click blank then click option'
Aproject_id
Blocation
Cqueue_name
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Passing location or queue name as the first argument causes errors.
Passing the client object instead of project ID.
3fill in blank
hard

Fix the error in the task creation code by completing the blank.

GCP
task = {
    'http_request': {
        'http_method': tasks_v2.HttpMethod.POST,
        'url': '[1]',
        'headers': {'Content-Type': 'application/json'},
        'body': b'{"message": "Hello"}'
    }
}
Drag options to blanks, or click blank then click option'
Aexample.com/taskhandler
Bhttps://example.com/taskhandler
Chttp://example.com/taskhandler
Dftp://example.com/taskhandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using URLs without https:// prefix causes errors.
Using http:// or ftp:// protocols is not allowed.
4fill in blank
hard

Fill both blanks to schedule a task with a delay of 60 seconds.

GCP
import datetime

schedule_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=[1])
task['schedule_time'] = schedule_time.[2]()
Drag options to blanks, or click blank then click option'
A60
Btimestamp
Cisoformat
Dnow
Attempts:
3 left
💡 Hint
Common Mistakes
Using isoformat instead of timestamp causes errors.
Using now() instead of timestamp() is incorrect.
5fill in blank
hard

Fill all three blanks to create and send a task to the queue.

GCP
response = client.[1](
    parent=[2],
    task=[3]
)
Drag options to blanks, or click blank then click option'
Acreate_task
Bparent
Ctask
Ddelete_task
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete_task instead of create_task.
Passing incorrect parameter names.