-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
main.go
83 lines (63 loc) · 1.71 KB
/
main.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/gosom/google-maps-scraper/runner"
"github.com/gosom/google-maps-scraper/runner/databaserunner"
"github.com/gosom/google-maps-scraper/runner/filerunner"
"github.com/gosom/google-maps-scraper/runner/installplaywright"
"github.com/gosom/google-maps-scraper/runner/lambdaaws"
"github.com/gosom/google-maps-scraper/runner/webrunner"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
runner.Banner()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
log.Println("Received signal, shutting down...")
cancel()
}()
cfg := runner.ParseConfig()
runnerInstance, err := runnerFactory(cfg)
if err != nil {
cancel()
os.Stderr.WriteString(err.Error() + "\n")
runner.Telemetry().Close()
os.Exit(1)
}
if err := runnerInstance.Run(ctx); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
_ = runnerInstance.Close(ctx)
runner.Telemetry().Close()
cancel()
os.Exit(1)
}
_ = runnerInstance.Close(ctx)
runner.Telemetry().Close()
cancel()
os.Exit(0)
}
func runnerFactory(cfg *runner.Config) (runner.Runner, error) {
switch cfg.RunMode {
case runner.RunModeFile:
return filerunner.New(cfg)
case runner.RunModeDatabase, runner.RunModeDatabaseProduce:
return databaserunner.New(cfg)
case runner.RunModeInstallPlaywright:
return installplaywright.New(cfg)
case runner.RunModeWeb:
return webrunner.New(cfg)
case runner.RunModeAwsLambda:
return lambdaaws.New(cfg)
case runner.RunModeAwsLambdaInvoker:
return lambdaaws.NewInvoker(cfg)
default:
return nil, fmt.Errorf("%w: %d", runner.ErrInvalidRunMode, cfg.RunMode)
}
}