@cryptotaxi247 / kubo / commits / 23e1b1db3

Use conditional for running provider online

License: MIT Signed-off-by: Michael Avila <davidmichaelavila@gmail.com>

Michael Avila committed May 6, 2019 at 16:16 UTC 23e1b1db3ac0cdf42653db0df4d126d79dcb8a43
1 file changed +19 -18
core/node/provider.go
+19 -18
@@ -37,23 +37,24 @@ func SimpleReprovider(reproviderInterval time.Duration) interface{} {
37 }
38
39 // SimpleProviderSys creates new provider system
40 -func SimpleProviderSys(lc fx.Lifecycle, p provider.Provider, r provider.Reprovider) provider.System {
41 - sys := provider.NewSystem(p, r)
42 - lc.Append(fx.Hook{
43 - OnStart: func(ctx context.Context) error {
44 - sys.Run()
45 - return nil
46 - },
47 - OnStop: func(ctx context.Context) error {
48 - return sys.Close()
49 - },
50 - })
51 - return sys
52 -}
40 +func SimpleProviderSys(isOnline bool) interface{} {
41 + return func(lc fx.Lifecycle, p provider.Provider, r provider.Reprovider) provider.System {
42 + sys := provider.NewSystem(p, r)
43 +
44 + if isOnline {
45 + lc.Append(fx.Hook{
46 + OnStart: func(ctx context.Context) error {
47 + sys.Run()
48 + return nil
49 + },
50 + OnStop: func(ctx context.Context) error {
51 + return sys.Close()
52 + },
53 + })
54 + }
55
54 -// SimpleOfflineProviderSys creates a new offline provider system
55 -func SimpleOfflineProviderSys(p provider.Provider, r provider.Reprovider) provider.System {
56 - return provider.NewSystem(p, r)
56 + return sys
57 + }
58 }
59
60 // ONLINE/OFFLINE
@@ -66,7 +67,7 @@ func OnlineProviders(useStrategicProviding bool, reprovideStrategy string, repro
67
68 return fx.Options(
69 SimpleProviders(reprovideStrategy, reprovideInterval),
69 - fx.Provide(SimpleProviderSys),
70 + fx.Provide(SimpleProviderSys(true)),
71 )
72 }
73
@@ -78,7 +79,7 @@ func OfflineProviders(useStrategicProviding bool, reprovideStrategy string, repr
79
80 return fx.Options(
81 SimpleProviders(reprovideStrategy, reprovideInterval),
81 - fx.Provide(SimpleOfflineProviderSys),
82 + fx.Provide(SimpleProviderSys(false)),
83 )
84 }
85