You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: using-tasks.html.md.erb
+46-68Lines changed: 46 additions & 68 deletions
Original file line number
Diff line number
Diff line change
@@ -5,70 +5,66 @@ owner: CAPI
5
5
6
6
<strong><%=modified_date%></strong>
7
7
8
-
This topic describes how to run tasks in Cloud Foundry.
9
-
10
-
Tasks are processes that are executed one time in the context of a given application. A task is only run at most once.
8
+
This topic describes how to run tasks in Cloud Foundry. A task is an application or script whose code is included as part of a deployed application, but runs independently in its own container.
11
9
12
10
## <aid='about-tasks'></a> About Tasks
13
11
14
-
In contrast to a long running process (LRP), tasks run for a finite amout of time, then stop. Tasks run in their own containers and are designed to use minimal resources. After the task runs, Cloud Foundry destroys the container running the task.
12
+
In contrast to a long running process (LRP), tasks run for a finite amout 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.
15
13
16
14
As a single-use object, a task can be checked for its state and for a success or failure message.
17
15
18
16
### <aid="use-cases"></a> Use Cases for Tasks
19
17
20
-
Tasks are used to perform one-off jobs. For example, you can use a task to:
18
+
Tasks are used to perform one-off jobs, which can include:
21
19
22
-
* Migrate a database
23
-
* Send an email
24
-
* Run a batch job
25
-
* Run a data processing script
26
-
* Process images
27
-
* Optimize a search index
28
-
* Upload data
29
-
* Backup data
30
-
* Download content
20
+
* Migrating a database
21
+
* Sending an email
22
+
* Running a batch job
23
+
* Running a data processing script
24
+
* Processing images
25
+
* Optimizing a search index
26
+
* Uploading data
27
+
* Backing-up data
28
+
* Downloading content
31
29
32
30
###<aid="task-proceses"></a> How Tasks Are Run
33
31
34
32
The life-cycle of a task is:
35
33
36
-
1. A user initiates a task in Cloud Foundry. A user can initiate a task in CF by using one of the following mechanisms:
37
-
* `cf run-task APPNAME TASK` command. See
34
+
1. A user initiates a task in Cloud Foundry using one of the following mechanisms:
35
+
* `cf run-task APPNAME "TASK"` command. See [Running Tasks](#run-tasks)
38
36
* Cloud Controller v3 API call. See the [Tasks](http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#tasks) API reference page.
39
37
* Cloud Foundry Java Client. See [Cloud Foundry Java Client Library](../buildpacks/java/java-client.html) and [Cloud Foundry Java Client](https://github.com/cloudfoundry/cf-java-client).
40
38
41
-
1. Cloud Foundry creates container specifically for the task.
42
-
1. Cloud Foundry runs the task on the container using the value provided to the `cf run-task` command
43
-
1. Cloud Foundry destroys container
39
+
1. Cloud Foundry creates a container specifically for the task.
40
+
1. Cloud Foundry runs the task on the container using the value passed to the `cf run-task` command.
41
+
1. Cloud Foundry destroys container.
42
+
43
+
When creating the container, Cloud Foundry uses the disk size and memory allocation specified for the parent application. The new container respects app, space, and organization-level memory quotas. The container also inherits environment variables, service bindings and security groups bound to the application. Tasks have a memory limit and a disk limit (global cloud foundry defaults for app memory in your bosh manifest or in ERT Application Developer Controls).
44
44
45
-
* A task includes the command to start the process, disk size, and memory allocation
46
-
* A task inherits environment variables, service bindings and security groups bound to the application
47
-
* Tasks respect app, space, and organization level memory quotas
48
-
* Tasks have a memory limit and a disk limit (global cloud foundry defaults for app memory in your bosh manifest or in ERT Application Developer Controls)
49
-
* Tasks are always executed asynchronously
45
+
Tasks are always executed asynchronously, meaning that they run independently from the parent application or other tasks run on the same application.
50
46
51
-
<pclass="note"><strong>Note</strong>: You cannot SSH into a running task.</p>
47
+
<pclass="note"><strong>Note</strong>: You cannot SSH into the container running a task.</p>
52
48
53
49
### Task Logging and Execution History
54
50
55
-
* Task execution history is retained for one month.
56
-
* A syslog drain attached to an app will receive task log output
57
-
* Stdout/stderr from the task will be available on the app’s firehose logs
51
+
Any data or messages the task outputs to STDOUT or STDERR is be available on the app’s firehose logs. A syslog drain attached to the app receives the task log output.
58
52
59
-
## <aid='manage-tasks'></a> Managing Tasks
53
+
The task execution history is retained for one month.
54
+
55
+
## <aid='manage-tasks'></a> Manage Tasks
60
56
61
57
* Admins can use the Cloud Controller v3 API to view all the tasks that are running in an org or space. See http://v3-apidocs.cloudfoundry.org/version/3.0.0/index.html#list-tasks
62
58
63
59
* Admins can set memory usage on a global level (link)
64
60
65
-
## <aid='run-tasks'></a>Running Tasks
61
+
## <aid='run-tasks'></a>Run a Task on an Application
66
62
67
63
You can use the cf CLI to run a task in the context of an application.
68
64
69
65
<pclass="note"><strong>Note</strong>: To run tasks with the cf CLI, you must install the cf CLI v6.23 (?) or later. See the <ahref="../cf-cli/install-go-cli.html">Installing the Cloud Foundry Command Line Interface</a> topic for information about downloading, installing, and uninstalling the cf CLI.</p>
70
66
71
-
To run a task on an application, first push your application. Then use the `cf run-task APPNAME TASK` command on your deployed application. For example:
67
+
To run a task on an application, first push your application. Then, use the `cf run-task APP-NAME TASK` command on your deployed application. For example:
72
68
73
69
<preclass="terminal">
74
70
$ cf run-task my-app "bin/rails db:migrate"
@@ -77,11 +73,24 @@ OK
77
73
Task 1 has been submitted successfully for execution.
78
74
</pre>
79
75
80
-
To re-run a task, you must create it as a new task.
76
+
To re-run a task, you must run it as a new task using the above command.
77
+
78
+
## <aid='list-tasks'></a> List Tasks Running on an Application
79
+
80
+
To list the tasks for a given application, run the `cf tasks APP-NAME`. For example:
81
+
82
+
<preclass="terminal">
83
+
$ cf tasks my-app
84
+
Getting tasks for app sl-rails-blog in org cf-docs-sandbox / space development as [email protected]...
85
+
OK
81
86
82
-
## <aid='list-tasks'></a> Listing Tasks
87
+
id name state start time command
88
+
3 ec964e1a SUCCEEDED Fri, 09 Dec 2016 23:14:58 UTC ./tasks/hello_world.sh
89
+
2 b84302eb SUCCEEDED Fri, 09 Dec 2016 23:09:11 UTC ./tasks/hello_world.sh
90
+
1 491c8a57 SUCCEEDED Fri, 09 Dec 2016 23:08:44 UTC ./tasks/hello_world.sh
91
+
</pre>
83
92
84
-
Tasks have the following states:
93
+
Each task has one of the following states:
85
94
86
95
<tableclass="nice" border="1">
87
96
<tr>
@@ -102,41 +111,10 @@ Tasks have the following states:
102
111
</tr>
103
112
</table>
104
113
105
-
## <aid='cancel-task'></a>
106
-
107
-
* A task is cancellable
108
-
109
-
110
-
To support running and managing tasks, the cf CLI supports the following commands:
111
-
112
-
113
-
114
-
* <strong>Comment</strong> I think it would be nice to include more how tasks are run. Is there a queue? Is the task run in a separate container?
115
-
* provide "architectural" information about how tasks work. For example, are they run in a separate container.
116
-
* different container, same code
117
-
118
-
For example, if you run cf run-task spring-music "echo blah", CF submits the task for execution and displays:
119
-
120
-
<code>
121
-
Creating task for app spring-music in org sleslie_pivotal / space development as [email protected]...
122
-
OK
123
-
124
-
Task 0 has been submitted successfully for execution.
125
-
</code>
126
-
127
-
To view the tasks running on an application:
128
-
129
-
cf tasks spring-music
130
-
131
-
id name state start time command
132
-
0 e4d3c654 SUCCEEDED Tue, 15 Nov 2016 19:25:55 UTC echo blah
133
-
134
-
135
-
136
-
Cloud Foundry
137
-
114
+
## <aid='cancel-task'></a> Cancel a Task
138
115
116
+
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.
139
117
140
118
## Sample Application
141
119
142
-
The <strong>github_link_to_example</strong> application demonstrates ...
0 commit comments