2023-07-31 17:34:32 +08:00
|
|
|
package init
|
2023-07-20 22:41:13 +08:00
|
|
|
|
2023-12-13 14:01:13 +08:00
|
|
|
import (
|
|
|
|
|
"context"
|
2024-01-22 11:35:28 +08:00
|
|
|
"mayfly-go/initialize"
|
2024-04-27 01:35:21 +08:00
|
|
|
"mayfly-go/internal/event"
|
2023-12-13 14:01:13 +08:00
|
|
|
"mayfly-go/internal/machine/application"
|
|
|
|
|
"mayfly-go/internal/machine/domain/entity"
|
2024-03-02 19:08:19 +08:00
|
|
|
"mayfly-go/internal/machine/infrastructure/persistence"
|
2024-01-22 11:35:28 +08:00
|
|
|
"mayfly-go/internal/machine/router"
|
2023-12-13 14:01:13 +08:00
|
|
|
"mayfly-go/pkg/eventbus"
|
|
|
|
|
"mayfly-go/pkg/global"
|
|
|
|
|
)
|
2023-07-20 22:41:13 +08:00
|
|
|
|
2024-01-22 11:35:28 +08:00
|
|
|
func init() {
|
2024-03-02 19:08:19 +08:00
|
|
|
initialize.AddInitIocFunc(func() {
|
|
|
|
|
persistence.InitIoc()
|
|
|
|
|
application.InitIoc()
|
|
|
|
|
})
|
2024-01-22 11:35:28 +08:00
|
|
|
initialize.AddInitRouterFunc(router.Init)
|
|
|
|
|
initialize.AddInitFunc(Init)
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:41:13 +08:00
|
|
|
func Init() {
|
|
|
|
|
application.GetMachineCronJobApp().InitCronJob()
|
2024-01-05 05:31:32 +00:00
|
|
|
|
2023-11-07 21:05:21 +08:00
|
|
|
application.GetMachineApp().TimerUpdateStats()
|
2023-12-13 14:01:13 +08:00
|
|
|
|
2024-01-15 20:51:41 +08:00
|
|
|
application.GetMachineTermOpApp().TimerDeleteTermOp()
|
|
|
|
|
|
2024-04-27 01:35:21 +08:00
|
|
|
global.EventBus.Subscribe(event.EventTopicDeleteMachine, "machineFile", func(ctx context.Context, event *eventbus.Event) error {
|
2023-12-13 14:01:13 +08:00
|
|
|
me := event.Val.(*entity.Machine)
|
|
|
|
|
return application.GetMachineFileApp().DeleteByCond(ctx, &entity.MachineFile{MachineId: me.Id})
|
|
|
|
|
})
|
|
|
|
|
|
2024-04-27 01:35:21 +08:00
|
|
|
global.EventBus.Subscribe(event.EventTopicDeleteMachine, "machineScript", func(ctx context.Context, event *eventbus.Event) error {
|
2023-12-13 14:01:13 +08:00
|
|
|
me := event.Val.(*entity.Machine)
|
|
|
|
|
return application.GetMachineScriptApp().DeleteByCond(ctx, &entity.MachineScript{MachineId: me.Id})
|
|
|
|
|
})
|
2023-07-20 22:41:13 +08:00
|
|
|
}
|