From f7c8d9d207076906eae07473ac8298f0bad6180f Mon Sep 17 00:00:00 2001 From: Chloe Hollingsworth Date: Thu, 7 Nov 2019 12:22:27 -0800 Subject: [PATCH] Style and formatting sweep --- using-tasks.html.md.erb | 74 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/using-tasks.html.md.erb b/using-tasks.html.md.erb index 14bb1ae2..622ea60a 100644 --- a/using-tasks.html.md.erb +++ b/using-tasks.html.md.erb @@ -3,13 +3,12 @@ title: Running Tasks owner: CAPI --- - - This topic describes how to run tasks in Cloud Foundry. A task is an app or script whose code is included as part of a deployed app, but runs independently in its own container. + ## About Tasks -In contrast to a long running process (LRP), tasks run for a finite amount of time, then stop. Tasks run in their own containers and are designed to use minimal resources. After a task runs, Cloud Foundry destroys the container running the task. +In contrast to a long-running process (LRP), tasks run for a finite amount of time, then stop. Tasks run in their own containers and are designed to use minimal resources. After a task runs, Cloud Foundry destroys the container running the task. As a single-use object, a task can be checked for its state and for a success or failure message. @@ -17,7 +16,7 @@ As a single-use object, a task can be checked for its state and for a success or ### Use Cases for Tasks -Tasks are used to perform one-off jobs, which include the following: +Tasks are used to perform one-off jobs, which include: * Migrating a database * Sending an email @@ -29,36 +28,39 @@ Tasks are used to perform one-off jobs, which include the following: * Backing-up data * Downloading content -### How Tasks Are Run +### How Tasks Are Run Tasks are always executed asynchronously, meaning that they run independently from the parent app or other tasks that run on the same app. The life-cycle of a task is as follows: 1. A user initiates a task in Cloud Foundry using one of the following mechanisms: - * `cf run-task APPNAME "TASK"` command. See the [Running Tasks](#run-tasks) section of this topic for more information. - * Cloud Controller v3 API call. See the [Tasks](http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#tasks) API reference page for more information. - * Cloud Foundry Java Client. See the [Cloud Foundry Java Client Library](../buildpacks/java/java-client.html) and [Cloud Foundry Java Client](https://github.com/cloudfoundry/cf-java-client) topics for more information. + * The `cf run-task APPNAME "TASK"` command. See the [Running Tasks](#run-tasks) section of this topic for more information. + * A Cloud Controller v3 API call. See the [Tasks](http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#tasks) API reference page for more information. + * The Cloud Foundry Java Client. For more information, see [Cloud Foundry Java Client Library](../buildpacks/java/java-client.html) and the [Cloud Foundry Java Client](https://github.com/cloudfoundry/cf-java-client) repository on GitHub. 1. Cloud Foundry creates a container specifically for the task. + 1. Cloud Foundry runs the task on the container using the value passed to the `cf run-task` command. + 1. Cloud Foundry destroys the container. The container also inherits environment variables, service bindings, and security groups bound to the app. -

Note: You cannot SSH into the container running a task.

+

Note: You cannot SSH into the container running a task.

-### Task Logging and Execution History +### Task Logging and Execution History Any data or messages the task outputs to STDOUT or STDERR is available on the app's firehose logs. A syslog drain attached to the app receives the task log output. The task execution history is retained for one month. + ## Manage Tasks -At the system level, a user with admin-level privileges can use the Cloud Controller v3 API to view all tasks that are running within an org or space. For more information, see the documentation for the [Cloud Controller v3 API](http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#list-tasks). +At the system level, a user with admin-level privileges can use the Cloud Controller v3 API to view all tasks that are running within an org or space. For more information, see the [Cloud Controller v3 API](http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#list-tasks) documentation. -In addition, admins can set the default memory and disk usage quotas for tasks on a global level. Initially, tasks use the same memory and disk usage defaults as apps. However, the default memory and disk allocations for tasks can be defined separately from the default app memory and disk allocations. +Additionally, admins can set the default memory and disk usage quotas for tasks on a global level. Initially, tasks use the same memory and disk usage defaults as apps. However, the default memory and disk allocations for tasks can be defined separately from the default app memory and disk allocations. <% if vars.platform_code == 'PCF' %> <%= partial '/pcf/core/2-7/tasks_rec_alloc_pcf' %> @@ -70,17 +72,22 @@ In addition, admins can set the default memory and disk usage quotas for tasks o You can use the Cloud Foundry Command Line Interface (cf CLI) to run a task in the context of an app. -

Note: To run tasks with the cf CLI, you must install cf CLI v6.23.0 or later. See the Installing the Cloud Foundry Command Line Interface topic for information about downloading, installing, and uninstalling the cf CLI.

+

Note: To run tasks with the cf CLI, you must install cf CLI v6.23.0 or later. For information about downloading, installing, and uninstalling the cf CLI, see the Installing the Cloud Foundry Command Line Interface.

+ +

Note: To run a task without starting the app, push the app with cf push -i 0 and then run the task. You can run the app later by scaling up its instance count.

-

Note: To run a task without starting the app, push the app with cf push -i 0 and then run the task. You can run the app later by scaling up its instance count.

+To run a task on an app: +1. Push your app by running: -To run a task on an app, perform the following steps: + ``` + cf push APP-NAME + ``` -1. Push your app: -
$ cf push APP-NAME
-1. Run your task on the deployed app: -
$ cf run-task APP-NAME "TASK" --name TASK-NAME
+1. Run your task on the deployed app by running: + ``` + cf run-task APP-NAME "TASK" --name TASK-NAME + ``` The following example runs a database migration as a task on the `my-app` app: @@ -91,7 +98,7 @@ OK Task 1 has been submitted successfully for execution. -

Note: To re-run a task, you must run it as a new task using the above command.

+

Note: To re-run a task, you must run it as a new task using the above command.

Use the `cf logs APP-NAME --recent` command to display the recent logs of the app and all its tasks. @@ -127,6 +134,7 @@ $ cf logs my-app --recent If your task name is unique, you can `grep` the output of the `cf logs` command for the task name to view task-specific logs. + ## List Tasks Running on an App To list the tasks for a given app, run the `cf tasks APP-NAME`. For example: @@ -143,28 +151,16 @@ id name state start time command Each task has one of the following states: - - - - - - - - - - - - - - - - - -
StateDescription
RUNNINGThe task is currently in progress.
FAILEDThe task did not complete. This state occurs when a task does not work correctly or a user cancels the task.
SUCCEEDEDThe task completed successfully.
+| State | Description | +| ----- | ----------- | +| RUNNING | The task is currently in progress. | +| FAILED | The task did not complete. This state occurs when a task does not work correctly or a user cancels the task. | +| SUCCEEDED | The task completed successfully. | + ## Cancel a Task -After running a task, you may be able to cancel it before it finishes. To cancel a running task, use the `cf terminate-task APP-NAME TASK-ID` command. For example: +After running a task, you may be able to cancel it before it finishes. To cancel a running task, run the `cf terminate-task APP-NAME TASK-ID` command. For example:
 $ cf terminate-task my-app 2