Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
861d6af1d7 | |||
ac2db05d06 | |||
f4904884ad | |||
7d0620fe3e | |||
3115c5feef | |||
10ca4f4671 |
8
actor.go
8
actor.go
@ -29,6 +29,14 @@ type Actor interface {
|
||||
Type() string
|
||||
}
|
||||
|
||||
// Named is any object with a name.
|
||||
type Named interface {
|
||||
// Name returns the name. This doesn't need to be the same as Type. It
|
||||
// must return the same string every time. It is used to differentiate
|
||||
// actors of the same type in logs.
|
||||
Name() string
|
||||
}
|
||||
|
||||
// FlagAdder is any object that can add [Flag]s to a [FlagSet]. Actors which
|
||||
// implement this interface will be called upon to add flags during and only
|
||||
// during the flag parsing phase.
|
||||
|
@ -41,6 +41,7 @@ type environment struct {
|
||||
logDirectory string
|
||||
configFile string
|
||||
verbose bool
|
||||
crash bool
|
||||
}
|
||||
|
||||
// running stores whether the environment is currently running.
|
||||
@ -282,7 +283,12 @@ func (this *environment) runRunnable(ctx context.Context, actor Runnable) (stopE
|
||||
for {
|
||||
// run actor
|
||||
lastStart := time.Now()
|
||||
err := panicWrapCtx(ctx, actor.Run)
|
||||
var err error
|
||||
if this.flags.crash {
|
||||
err = actor.Run(ctx)
|
||||
} else {
|
||||
err = panicWrapCtx(ctx, actor.Run)
|
||||
}
|
||||
|
||||
// detect context cancellation
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
|
4
ini.go
4
ini.go
@ -162,7 +162,7 @@ func configFiles(program string) ([]string, error) {
|
||||
userConfig, err := os.UserConfigDir()
|
||||
if err != nil { return nil, err }
|
||||
return []string {
|
||||
filepath.Join("/etc", program),
|
||||
filepath.Join(userConfig, program),
|
||||
filepath.Join("/etc", program, program + ".conf"),
|
||||
filepath.Join(userConfig, program, program + ".conf"),
|
||||
}, nil
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ func (this *environment) phase10FlagParsing() bool {
|
||||
flagLogDirectory := set.Flag('l', "log-directory", "Write logs to the specified directory", cli.ValString)
|
||||
flagConfigFile := set.Flag('c', "config-file", "Use this configuration file", cli.ValString)
|
||||
flagVerbose := set.Flag('v', "verbose", "Enable verbose output/logging", nil)
|
||||
flagCrash := set.Flag(0, "crash", "Crash when an actor panics", nil)
|
||||
|
||||
// ask actors to add flags
|
||||
actors, done := this.actors.RBorrow()
|
||||
@ -60,6 +61,9 @@ func (this *environment) phase10FlagParsing() bool {
|
||||
if _, ok := flagVerbose.First(); ok {
|
||||
this.flags.verbose = true
|
||||
}
|
||||
if _, ok := flagCrash.First(); ok {
|
||||
this.flags.crash = true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
6
util.go
6
util.go
@ -77,7 +77,11 @@ func logActors (actors iter.Seq[Actor]) {
|
||||
}
|
||||
types := make(map[string] int)
|
||||
for actor := range actors {
|
||||
types[actor.Type()] += 1
|
||||
typ := actor.Type()
|
||||
if named, ok := actor.(Named); ok {
|
||||
typ = fmt.Sprintf("%s/%s", typ, named.Name())
|
||||
}
|
||||
types[typ] += 1
|
||||
}
|
||||
for typ, count := range types {
|
||||
if count > 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user