Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The CloudTasksClient constructor accepts client_options as an optional argument. Passing None means default options are used.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The queue_path method requires the project ID as the first argument.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using URLs without https:// prefix causes errors.
Using http:// or ftp:// protocols is not allowed.
✗ Incorrect
The URL must be a valid HTTPS URL starting with https:// for Cloud Tasks HTTP requests.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isoformat instead of timestamp causes errors.
Using now() instead of timestamp() is incorrect.
✗ Incorrect
To schedule a task, add 60 seconds delay and convert to a timestamp using timestamp().
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete_task instead of create_task.
Passing incorrect parameter names.
✗ Incorrect
The method to send a task is create_task, with parameters parent and task.