blob: d3e64d6f9df58c2970357ae9af0077c9fba4e4d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// skate-from-unstructured tries to parse various pieces of information from
// the unstructured field in refs.
package main
import (
"flag"
"log"
"os"
"runtime"
"github.com/segmentio/encoding/json"
"gitlab.com/internetarchive/refcat/skate"
"gitlab.com/internetarchive/refcat/skate/parallel"
)
var (
numWorkers = flag.Int("w", runtime.NumCPU(), "number of workers")
batchSize = flag.Int("b", 100000, "batch size")
)
func main() {
pp := parallel.NewProcessor(os.Stdin, os.Stdout, func(p []byte) ([]byte, error) {
var (
ref skate.Ref
err error
)
if err = json.Unmarshal(p, &ref); err != nil {
return nil, err
}
if err = skate.ParseUnstructured(&ref); err != nil {
return nil, err
}
return skate.JsonMarshalNewline(&ref)
})
pp.NumWorkers = *numWorkers
pp.BatchSize = *batchSize
if err := pp.Run(); err != nil {
log.Fatal(err)
}
}
|