Skip to content

Commit 7ddd7c5

Browse files
Vitexusclaude
andcommitted
feat(job): read stdout/stderr from job_output_lines table
GetCommand: always inject stdout/stderr from job_output_lines so callers see the full output even after the columns are removed from the job table. ListCommand: hydrate stdout/stderr per-job when explicitly requested via --fields; skip hydration otherwise to keep list queries fast. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 95fde08 commit 7ddd7c5

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/Command/Job/GetCommand.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5252

5353
$job = new Job((int) $id);
5454
$fields = $input->getOption('fields');
55+
$fieldsArray = $fields ? array_map('trim', explode(',', $fields)) : [];
5556

56-
if ($fields) {
57-
$fieldsArray = explode(',', $fields);
58-
$data = array_filter($job->getData(), static fn ($key) => \in_array($key, $fieldsArray, true), \ARRAY_FILTER_USE_KEY);
59-
} else {
60-
$data = $job->getData();
57+
// Base data from the DB row (no longer contains stdout/stderr columns)
58+
$data = $job->getData();
59+
60+
// Always inject stdout/stderr from job_output_lines so callers get the full picture
61+
if (empty($fieldsArray) || \in_array('stdout', $fieldsArray, true)) {
62+
$data['stdout'] = $job->getOutput();
63+
}
64+
65+
if (empty($fieldsArray) || \in_array('stderr', $fieldsArray, true)) {
66+
$data['stderr'] = $job->getErrorOutput();
67+
}
68+
69+
if ($fieldsArray) {
70+
$data = array_filter($data, static fn ($key) => \in_array($key, $fieldsArray, true), \ARRAY_FILTER_USE_KEY);
6171
}
6272

6373
if ($format === 'json') {

src/Command/Job/ListCommand.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116116
unset($jobData);
117117

118118
$fields = $input->getOption('fields');
119+
$fieldList = !empty($fields) ? array_map('trim', explode(',', $fields)) : [];
119120

120-
if (!empty($fields)) {
121-
$fieldList = array_map('trim', explode(',', $fields));
121+
// Hydrate stdout/stderr from job_output_lines when explicitly requested
122+
$needsStdout = empty($fieldList) ? false : \in_array('stdout', $fieldList, true);
123+
$needsStderr = empty($fieldList) ? false : \in_array('stderr', $fieldList, true);
124+
125+
if ($needsStdout || $needsStderr) {
126+
foreach ($jobs as &$jobRow) {
127+
$jobObj = new Job((int) $jobRow['id']);
128+
129+
if ($needsStdout) {
130+
$jobRow['stdout'] = $jobObj->getOutput();
131+
}
132+
133+
if ($needsStderr) {
134+
$jobRow['stderr'] = $jobObj->getErrorOutput();
135+
}
136+
}
137+
138+
unset($jobObj);
139+
}
140+
141+
if (!empty($fieldList)) {
122142
$jobs = array_map(static fn ($job) => array_intersect_key($job, array_flip($fieldList)), $jobs);
123143
}
124144

0 commit comments

Comments
 (0)