Skip to content

Commit 6c004b7

Browse files
committed
Renamed "tasks" to "items"
1 parent 261a12c commit 6c004b7

File tree

4 files changed

+84
-84
lines changed

4 files changed

+84
-84
lines changed

README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ How it works
77
------------
88

99
When you launch a command with multi-processing enabled (`--processes 2`), a
10-
master process fetches *tasks* and distributes them across the given number of
11-
child processes. Child processes are killed after a fixed number of tasks
10+
master process fetches *items* and distributes them across the given number of
11+
child processes. Child processes are killed after a fixed number of items
1212
(a *segment*) in order to prevent them from slowing down over time.
1313

1414
Optionally, the work of child processes can be split down into further chunks
@@ -46,31 +46,31 @@ class ImportMoviesCommand extends ContainerAwareCommand
4646
self::configureParallelization($this);
4747
}
4848

49-
protected function fetchTasks(InputInterface $input): array
49+
protected function fetchItems(InputInterface $input): array
5050
{
5151
// open up the file and read movie data...
5252

53-
// return tasks as strings
53+
// return items as strings
5454
return [
5555
'{"id": 1, "name": "Star Wars"}',
5656
'{"id": 2, "name": "Django Unchained"}',
5757
// ...
5858
];
5959
}
6060

61-
protected function runSingleCommand(string $task, InputInterface $input, OutputInterface $output): void
61+
protected function runSingleCommand(string $item, InputInterface $input, OutputInterface $output): void
6262
{
63-
$movieData = unserialize($task);
63+
$movieData = unserialize($item);
6464

6565
// insert into the database
6666
}
6767

68-
protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $tasks): void
68+
protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $items): void
6969
{
7070
// flush the database and clear the entity manager
7171
}
7272

73-
protected function getTaskName(int $count): string
73+
protected function getItemName(int $count): string
7474
{
7575
return 1 === $count ? 'movie' : 'movies';
7676
}
@@ -99,27 +99,27 @@ Processing 2768 movies in segments of 50, batches of 50, 56 rounds, 56 batches i
9999
Processed 2768 movies.
100100
```
101101

102-
Tasks
102+
Items
103103
-----
104104

105-
The master process fetches all the tasks that need to be processed and passes
106-
them to the child processes through their Standard Input. Hence tasks must
105+
The master process fetches all the items that need to be processed and passes
106+
them to the child processes through their Standard Input. Hence items must
107107
fulfill two requirements:
108108

109-
* Tasks must be strings
110-
* Tasks must not contain newlines
109+
* Items must be strings
110+
* Items must not contain newlines
111111

112-
Typically, you want to keep tasks small in order to offload processing from the
113-
master process to the child process. Some typical examples for tasks:
112+
Typically, you want to keep items small in order to offload processing from the
113+
master process to the child process. Some typical examples for items:
114114

115115
* The master process reads a file and passes the lines to the child processes
116116
* The master processes fetches IDs of database rows that need to be updated and passes them to the child processes
117117

118118
Segments
119119
--------
120120

121-
When you run a command with multi-processing enabled, the tasks returned by
122-
`fetchTasks()` are split into segments of a fixed size. Each child processes
121+
When you run a command with multi-processing enabled, the items returned by
122+
`fetchItems()` are split into segments of a fixed size. Each child processes
123123
processes a single segment and kills itself after that.
124124

125125
By default, the segment size is the same as the batch size (see below), but you
@@ -146,12 +146,12 @@ To run code before/after each batch, override the hooks `runBeforeBatch()` and
146146
`runAfterBatch()`:
147147

148148
```php
149-
protected function runBeforeBatch(InputInterface $input, OutputInterface $output, array $tasks): void
149+
protected function runBeforeBatch(InputInterface $input, OutputInterface $output, array $items): void
150150
{
151151
// e.g. fetch needed resources collectively
152152
}
153153

154-
protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $tasks): void
154+
protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $items): void
155155
{
156156
// e.g. flush database changes and free resources
157157
}
@@ -177,8 +177,8 @@ Method | Scope | Description
177177
------------------------------------------- | ----------------- | ---------------------------------------------
178178
`runBeforeFirstCommand($input, $output)` | Master process | Run before any child process is spawned
179179
`runAfterLastCommand($input, $output)` | Master process | Run after all child processes have completed
180-
`runBeforeBatch($input, $output, $tasks)` | Child process | Run before each batch in the child process
181-
`runAfterBatch($input, $output, $tasks)` | Child process | Run after each batch in the child process
180+
`runBeforeBatch($input, $output, $items)` | Child process | Run before each batch in the child process
181+
`runAfterBatch($input, $output, $items)` | Child process | Run after each batch in the child process
182182

183183
Authors
184184
-------

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.0",
13+
"php": "^7.1",
1414
"symfony/console": "^3.0 || ^4.0",
1515
"symfony/dependency-injection": "^3.0 || ^4.0",
1616
"symfony/process": "^3.0 || ^4.0",

0 commit comments

Comments
 (0)