Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cloud Tasks] split snippet methods #2332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions appengine/flexible/tasks/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,44 @@ def create_task_with_name(project, location, queue, task_name):


def delete_task(project, location, queue):
# [START taskqueues_setup]
# [START taskqueues_deleting_tasks]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'
# [END taskqueues_setup]

# [START taskqueues_deleting_tasks]
task_path = client.task_path(project, location, queue, 'foo')
response = client.delete_task(task_path)
# [END taskqueues_deleting_tasks]
return response


def purge_queue(project, location, queue):
# [START taskqueues_purging_tasks]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

queue_path = client.queue_path(project, location, queue)
response = client.purge_queue(queue_path)
# [END taskqueues_purging_tasks]
return response


def pause_queue(project, location, queue):
# [START taskqueues_pause_queue]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

queue_path = client.queue_path(project, location, queue)
response = client.pause_queue(queue_path)
# [END taskqueues_pause_queues]
Expand Down
22 changes: 19 additions & 3 deletions appengine/flexible/tasks/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,30 @@ def test_create_task_with_name():

@pytest.mark.order6
def test_delete_task():
result = snippets.delete_task(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert result is None


@pytest.mark.order7
def test_purge_queue():
name = "projects/{}/locations/{}/queues/{}".format(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
result = snippets.delete_task(
result = snippets.purge_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert name in result.name


@pytest.mark.order7
@pytest.mark.order8
def test_pause_queue():
name = "projects/{}/locations/{}/queues/{}".format(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
result = snippets.pause_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert name in result.name


@pytest.mark.order9
def test_delete_queue():
result = snippets.delete_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
Expand All @@ -89,7 +105,7 @@ def test_delete_queue():
assert result is None


@pytest.mark.order8
@pytest.mark.order10
def test_retry_task():
QUEUE_SIZE = 3
QUEUE_NAME = []
Expand Down