forked from mtusi2026/mtusi2026lab5
feat(worker): enforce image processing timeout with child process
This commit is contained in:
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -17,6 +19,22 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
maxPixels := flag.Int("process-image", 0, "process an image from stdin with the given pixel limit")
|
||||
flag.Parse()
|
||||
|
||||
if *maxPixels > 0 {
|
||||
if err := worker.ProcessImage(*maxPixels); err != nil {
|
||||
if errors.Is(err, worker.ErrInvalidSource) {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, "process image:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "worker:", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user