mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Merge pull request #44 from lippserd/move-factories-away-from-main
Move factories away from main
This commit is contained in:
commit
a51ec8a4ac
3 changed files with 67 additions and 59 deletions
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"github.com/icinga/icingadb/internal/command"
|
||||
"github.com/icinga/icingadb/pkg/contracts"
|
||||
"github.com/icinga/icingadb/pkg/icingadb"
|
||||
"github.com/icinga/icingadb/pkg/icingadb/history"
|
||||
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
|
||||
|
|
@ -52,66 +51,11 @@ func main() {
|
|||
go func() {
|
||||
g, synctx := errgroup.WithContext(hactx)
|
||||
|
||||
for _, factoryFunc := range []contracts.EntityFactoryFunc{
|
||||
v1.NewActionUrl,
|
||||
v1.NewCheckcommand,
|
||||
v1.NewCheckcommandArgument,
|
||||
v1.NewCheckcommandCustomvar,
|
||||
v1.NewCheckcommandEnvvar,
|
||||
v1.NewComment,
|
||||
v1.NewCustomvar,
|
||||
v1.NewDowntime,
|
||||
v1.NewEndpoint,
|
||||
v1.NewEventcommand,
|
||||
v1.NewEventcommandArgument,
|
||||
v1.NewEventcommandCustomvar,
|
||||
v1.NewEventcommandEnvvar,
|
||||
v1.NewHost,
|
||||
v1.NewHostCustomvar,
|
||||
v1.NewHostgroup,
|
||||
v1.NewHostgroupCustomvar,
|
||||
v1.NewHostgroupMember,
|
||||
v1.NewIconImage,
|
||||
v1.NewNotesUrl,
|
||||
v1.NewNotification,
|
||||
v1.NewNotificationcommand,
|
||||
v1.NewNotificationcommandArgument,
|
||||
v1.NewNotificationcommandCustomvar,
|
||||
v1.NewNotificationcommandEnvvar,
|
||||
v1.NewNotificationCustomvar,
|
||||
v1.NewNotificationRecipient,
|
||||
v1.NewNotificationUser,
|
||||
v1.NewNotificationUsergroup,
|
||||
v1.NewService,
|
||||
v1.NewServiceCustomvar,
|
||||
v1.NewServicegroup,
|
||||
v1.NewServicegroupCustomvar,
|
||||
v1.NewServicegroupMember,
|
||||
v1.NewTimeperiod,
|
||||
v1.NewTimeperiodCustomvar,
|
||||
v1.NewTimeperiodOverrideExclude,
|
||||
v1.NewTimeperiodOverrideInclude,
|
||||
v1.NewTimeperiodRange,
|
||||
v1.NewUser,
|
||||
v1.NewUserCustomvar,
|
||||
v1.NewUsergroup,
|
||||
v1.NewUsergroupCustomvar,
|
||||
v1.NewUsergroupMember,
|
||||
v1.NewZone,
|
||||
} {
|
||||
factoryFunc := factoryFunc
|
||||
|
||||
ff := func() contracts.Entity {
|
||||
v := factoryFunc()
|
||||
if initer, ok := v.(contracts.Initer); ok {
|
||||
initer.Init()
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
for _, factory := range v1.Factories {
|
||||
factory := factory
|
||||
|
||||
g.Go(func() error {
|
||||
return s.Sync(synctx, ff)
|
||||
return s.Sync(synctx, factory.WithInit)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,17 @@ type Checksumer interface {
|
|||
// EntityFactoryFunc knows how to create an Entity.
|
||||
type EntityFactoryFunc func() Entity
|
||||
|
||||
// WithInit calls Init() on the created Entity if applicable.
|
||||
func (f EntityFactoryFunc) WithInit() Entity {
|
||||
e := f()
|
||||
|
||||
if initer, ok := e.(Initer); ok {
|
||||
initer.Init()
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// Waiter implements the Wait method,
|
||||
// which blocks until execution is complete.
|
||||
type Waiter interface {
|
||||
|
|
|
|||
53
pkg/icingadb/v1/v1.go
Normal file
53
pkg/icingadb/v1/v1.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/icinga/icingadb/pkg/contracts"
|
||||
)
|
||||
|
||||
var Factories = []contracts.EntityFactoryFunc{
|
||||
NewActionUrl,
|
||||
NewCheckcommand,
|
||||
NewCheckcommandArgument,
|
||||
NewCheckcommandCustomvar,
|
||||
NewCheckcommandEnvvar,
|
||||
NewComment,
|
||||
NewCustomvar,
|
||||
NewDowntime,
|
||||
NewEndpoint,
|
||||
NewEventcommand,
|
||||
NewEventcommandArgument,
|
||||
NewEventcommandCustomvar,
|
||||
NewEventcommandEnvvar,
|
||||
NewHost,
|
||||
NewHostCustomvar,
|
||||
NewHostgroup,
|
||||
NewHostgroupCustomvar,
|
||||
NewHostgroupMember,
|
||||
NewIconImage,
|
||||
NewNotesUrl,
|
||||
NewNotification,
|
||||
NewNotificationcommand,
|
||||
NewNotificationcommandArgument,
|
||||
NewNotificationcommandCustomvar,
|
||||
NewNotificationcommandEnvvar,
|
||||
NewNotificationCustomvar,
|
||||
NewNotificationRecipient,
|
||||
NewNotificationUser,
|
||||
NewNotificationUsergroup,
|
||||
NewService,
|
||||
NewServiceCustomvar,
|
||||
NewServicegroup,
|
||||
NewServicegroupCustomvar,
|
||||
NewServicegroupMember,
|
||||
NewTimeperiod,
|
||||
NewTimeperiodCustomvar,
|
||||
NewTimeperiodOverrideExclude,
|
||||
NewTimeperiodOverrideInclude,
|
||||
NewTimeperiodRange,
|
||||
NewUser,
|
||||
NewUserCustomvar,
|
||||
NewUsergroup,
|
||||
NewUsergroupCustomvar,
|
||||
NewUsergroupMember,
|
||||
NewZone,
|
||||
}
|
||||
Loading…
Reference in a new issue