@@ -7,8 +7,8 @@ How it works
7
7
------------
8
8
9
9
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
12
12
(a * segment* ) in order to prevent them from slowing down over time.
13
13
14
14
Optionally, the work of child processes can be split down into further chunks
@@ -46,31 +46,31 @@ class ImportMoviesCommand extends ContainerAwareCommand
46
46
self::configureParallelization($this);
47
47
}
48
48
49
- protected function fetchTasks (InputInterface $input): array
49
+ protected function fetchItems (InputInterface $input): array
50
50
{
51
51
// open up the file and read movie data...
52
52
53
- // return tasks as strings
53
+ // return items as strings
54
54
return [
55
55
'{"id": 1, "name": "Star Wars"}',
56
56
'{"id": 2, "name": "Django Unchained"}',
57
57
// ...
58
58
];
59
59
}
60
60
61
- protected function runSingleCommand(string $task , InputInterface $input, OutputInterface $output): void
61
+ protected function runSingleCommand(string $item , InputInterface $input, OutputInterface $output): void
62
62
{
63
- $movieData = unserialize($task );
63
+ $movieData = unserialize($item );
64
64
65
65
// insert into the database
66
66
}
67
67
68
- protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $tasks ): void
68
+ protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $items ): void
69
69
{
70
70
// flush the database and clear the entity manager
71
71
}
72
72
73
- protected function getTaskName (int $count): string
73
+ protected function getItemName (int $count): string
74
74
{
75
75
return 1 === $count ? 'movie' : 'movies';
76
76
}
@@ -99,27 +99,27 @@ Processing 2768 movies in segments of 50, batches of 50, 56 rounds, 56 batches i
99
99
Processed 2768 movies.
100
100
```
101
101
102
- Tasks
102
+ Items
103
103
-----
104
104
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
107
107
fulfill two requirements:
108
108
109
- * Tasks must be strings
110
- * Tasks must not contain newlines
109
+ * Items must be strings
110
+ * Items must not contain newlines
111
111
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 :
114
114
115
115
* The master process reads a file and passes the lines to the child processes
116
116
* The master processes fetches IDs of database rows that need to be updated and passes them to the child processes
117
117
118
118
Segments
119
119
--------
120
120
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
123
123
processes a single segment and kills itself after that.
124
124
125
125
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
146
146
` runAfterBatch() ` :
147
147
148
148
``` php
149
- protected function runBeforeBatch(InputInterface $input, OutputInterface $output, array $tasks ): void
149
+ protected function runBeforeBatch(InputInterface $input, OutputInterface $output, array $items ): void
150
150
{
151
151
// e.g. fetch needed resources collectively
152
152
}
153
153
154
- protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $tasks ): void
154
+ protected function runAfterBatch(InputInterface $input, OutputInterface $output, array $items ): void
155
155
{
156
156
// e.g. flush database changes and free resources
157
157
}
@@ -177,8 +177,8 @@ Method | Scope | Description
177
177
------------------------------------------- | ----------------- | ---------------------------------------------
178
178
` runBeforeFirstCommand($input, $output) ` | Master process | Run before any child process is spawned
179
179
` 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
182
182
183
183
Authors
184
184
-------
0 commit comments