Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Latest
* [#343](https://github.com/cleverage/process-bundle/issues/343) The temporary files of `FileSplitterTask` (`file_splitter`), `CsvSplitterTask` (`csv_splitter`) and of the JSON buffer of `ProcessLauncherTask` (`json_buffering`) are created with a random name, exclusively (an existing path, symbolic links included, is never reused) and readable by their owner only, instead of a name derived from the time (`uniqid()`), opened in `w` mode with the permissions of the umask. Update documentation, add tests.
* [#331](https://github.com/cleverage/process-bundle/issues/331) `ProcessManager`: the iterable tasks that produced items and the blocking tasks waiting for `proceed()` are tracked by task configuration instead of task code, and forgotten when their process ends. A task of a sub-process (`process_executor`) with the same code as a task of the parent no longer makes the parent lose the output of its blocking task (without error) or skip the flush at the end of its iteration (merged batches), and a failed sub-process no longer leaves its tasks to its next execution. Add tests.
* [#333](https://github.com/cleverage/process-bundle/issues/333) `ProcessManager`: restore the previous task configuration (`getTaskConfiguration()`, read by the log processors for `task_code` and `task_service`) when a task, an initialization, a finalization or a sub-process ends. The logs of an iterable task no longer lose their task after its first item, and the logs of a parent process are no longer attributed to a task of its sub-process; the failing task is kept for the logs of the process failure. Add tests.
* [#335](https://github.com/cleverage/process-bundle/issues/335) `LineReaderTask` (`line_reader`) and `InputLineReaderTask` (`input_line_reader`): the last line of a file that does not end with a line break is no longer lost. Add tests.

v5.4.1
-----
Expand Down
3 changes: 2 additions & 1 deletion src/Task/File/LineReaderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function next(ProcessState $state): bool
throw new LogicException('No File initialized');
}

$endOfFile = $this->file->eof();
// Not eof(): with READ_AHEAD, the end of the file is reached when the last line is read, before it is emitted
$endOfFile = !$this->file->valid();
if ($endOfFile) {
// Release the file to allow the following iteration to read it again
$this->file = null;
Expand Down
13 changes: 13 additions & 0 deletions tests/Task/File/LineReaderTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function setUp(): void
$filesystem = new Filesystem();
$filesystem->dumpFile($this->tmpDir.'/a.txt', "a1\na2\n");
$filesystem->dumpFile($this->tmpDir.'/b.txt', "b1\n");
$filesystem->dumpFile($this->tmpDir.'/no_final_line_break.txt', "l1\n\nl3\r\nl4");
}

protected function tearDown(): void
Expand All @@ -60,6 +61,18 @@ public function testSameFileIsReadAgainOnSecondExecution(): void
);
}

public function testTheLastLineIsReadWithoutFinalLineBreak(): void
{
self::assertSame(
["l1\n", "\n", "l3\r\n", 'l4'],
$this->iterate(new LineReaderTask(), $this->createState(['filename' => $this->tmpDir.'/no_final_line_break.txt'])),
);
self::assertSame(
["l1\n", "\n", "l3\r\n", 'l4'],
$this->iterate(new InputLineReaderTask(), $this->createState([]), $this->tmpDir.'/no_final_line_break.txt'),
);
}

public function testInputLineReaderReadsSameFileTwice(): void
{
$task = new InputLineReaderTask();
Expand Down
Loading