Skip to content
Permalink
f92229e1fe
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
113 lines (104 sloc) 2.35 KB
package main
import (
"context"
"github.com/getsentry/sentry-go"
"go.uber.org/fx"
"go.uber.org/zap"
"time"
"vlink.dev/eoefans/internal/app/spider"
"vlink.dev/eoefans/internal/app/spider/health"
"vlink.dev/eoefans/internal/launcher"
"vlink.dev/eoefans/internal/pkg/database"
"vlink.dev/eoefans/internal/pkg/log"
)
func main() {
launcher.Run(newSpider())
}
func newSpider() fx.Option {
return fx.Options(
database.Provide(),
fx.Invoke(lc),
spider.Provide(),
)
}
func lc(
lifecycle fx.Lifecycle,
spiderVideo *spider.Video,
spiderUpdate *spider.Update,
spiderPicture *spider.Picture,
spiderUpdatePicture *spider.UpdateDynamic,
checkServer *health.CheckServer,
shutdown fx.Shutdowner,
logger *zap.Logger,
client *sentry.Client,
sentryCfg *log.SentryConfig,
) {
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
*logger = *log.ModifyToSentryLogger(logger, sentryCfg, client)
return nil
},
OnStop: func(ctx context.Context) error {
client.Flush(2 * time.Second)
return nil
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return spiderVideo.Run(ctx)
},
OnStop: func(ctx context.Context) error {
if err := spiderVideo.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return spiderUpdate.Run(ctx)
},
OnStop: func(ctx context.Context) error {
if err := spiderUpdate.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return spiderPicture.Run(ctx)
},
OnStop: func(ctx context.Context) error {
if err := spiderPicture.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return spiderUpdatePicture.Run(ctx)
},
OnStop: func(ctx context.Context) error {
if err := spiderUpdatePicture.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
go func() {
_ = checkServer.Run(ctx)
}()
return nil
},
OnStop: func(ctx context.Context) error {
if err := checkServer.Stop(ctx); err != nil {
return err
}
return shutdown.Shutdown()
},
})
}