Skip to content

Commit 5ba1882

Browse files
committed
Addresses Review Comments
1 parent f0ac865 commit 5ba1882

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmd/runner/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (h *handler) parsePortfolio(ctx context.Context, taskID task.ID, req *task.
290290
// NOTE: This code could benefit from some concurrency, but I'm opting not to prematurely optimize.
291291
var out []*task.ParsePortfolioResponseItem
292292
for _, p := range paths {
293-
lineCount, err := countLines(p)
293+
lineCount, err := countCSVLines(p)
294294
if err != nil {
295295
return fmt.Errorf("failed to count lines in file %q: %w", p, err)
296296
}
@@ -338,7 +338,7 @@ func (h *handler) parsePortfolio(ctx context.Context, taskID task.ID, req *task.
338338
return nil
339339
}
340340

341-
func countLines(path string) (int, error) {
341+
func countCSVLines(path string) (int, error) {
342342
file, err := os.Open(path)
343343
if err != nil {
344344
return 0, fmt.Errorf("opening file failed: %w", err)
@@ -352,7 +352,8 @@ func countLines(path string) (int, error) {
352352
if err := scanner.Err(); err != nil {
353353
return 0, fmt.Errorf("scanner.error returned: %w", err)
354354
}
355-
return lineCount, nil
355+
// Subtract 1 for the header row
356+
return lineCount - 1, nil
356357
}
357358

358359
func createReportReq() (*task.CreateReportRequest, error) {

cmd/runner/taskrunner/taskrunner.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,22 @@ func New(cfg *Config) (*TaskRunner, error) {
8383
}
8484

8585
func (tr *TaskRunner) ParsePortfolio(ctx context.Context, req *task.ParsePortfolioRequest) (task.ID, task.RunnerID, error) {
86-
var taskBuffer bytes.Buffer
87-
if err := json.NewEncoder(&taskBuffer).Encode(req); err != nil {
86+
var buf bytes.Buffer
87+
if err := json.NewEncoder(&buf).Encode(req); err != nil {
8888
return "", "", fmt.Errorf("failed to encode ParsePortfolioRequest: %w", err)
8989
}
90+
value := buf.String()
91+
if len(value) > 128*1024 {
92+
return "", "", fmt.Errorf("ParsePortfolioRequest is too large: %d bytes > 128 kb", len(value))
93+
}
9094
return tr.run(ctx, []task.EnvVar{
9195
{
9296
Key: "TASK_TYPE",
9397
Value: string(task.ParsePortfolio),
9498
},
9599
{
96100
Key: "PARSE_PORTFOLIO_REQUEST",
97-
Value: taskBuffer.String(),
101+
Value: buf.String(),
98102
},
99103
})
100104
}

0 commit comments

Comments
 (0)