Event replay and cleanup
This commit is contained in:
parent
2560410820
commit
97bf66c191
8 changed files with 447 additions and 39 deletions
|
|
@ -2,9 +2,10 @@ package state
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
|
||||
"gitlab.com/whom/bingobot/internal/config"
|
||||
"gitlab.com/whom/bingobot/internal/logging"
|
||||
)
|
||||
|
||||
|
|
@ -102,6 +103,12 @@ func (ve VoteEvent) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ve VoteEvent) Disposable() bool {
|
||||
// will be implemented with democracy module
|
||||
logging.Warn("unimplemented: VoteEvent::Disposable")
|
||||
return false
|
||||
}
|
||||
|
||||
type UserEvent struct {
|
||||
uid string
|
||||
created time.Time
|
||||
|
|
@ -129,6 +136,13 @@ func (ue UserEvent) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ue UserEvent) Disposable() bool {
|
||||
// when I make a module for challenges, restorations, and UserActives
|
||||
// then I should implement this
|
||||
logging.Warn("unimplemented: UserEvent::Disposable")
|
||||
return false
|
||||
}
|
||||
|
||||
type ChallengeEvent struct {
|
||||
UserEvent
|
||||
}
|
||||
|
|
@ -167,9 +181,48 @@ func (ua UserActiveEvent) Type() EventType {
|
|||
return UserActive
|
||||
}
|
||||
|
||||
func (ua UserActiveEvent) Disposable() bool {
|
||||
return (time.Since(ua.created).Hours() / 24) >= float64(config.Get().UserEventLifespanDays)
|
||||
}
|
||||
|
||||
func NewUserActiveEvent(user string) UserActiveEvent {
|
||||
return UserActiveEvent{UserEvent{
|
||||
uid: user,
|
||||
created: time.Now(),
|
||||
}}
|
||||
}
|
||||
|
||||
const (
|
||||
TestEventDisposeKey = "dispose"
|
||||
TestEventIDKey = "id"
|
||||
)
|
||||
|
||||
type TestEvent struct {
|
||||
Dispose bool
|
||||
ID int
|
||||
}
|
||||
|
||||
func (te TestEvent) Type() EventType {
|
||||
return Test
|
||||
}
|
||||
|
||||
func (te TestEvent) Time() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (te TestEvent) Data() map[string]string {
|
||||
m := map[string]string{}
|
||||
if te.Dispose {
|
||||
m[TestEventDisposeKey] = "t"
|
||||
}
|
||||
m[TestEventIDKey] = fmt.Sprintf("%d", te.ID)
|
||||
return m
|
||||
}
|
||||
|
||||
func (te TestEvent) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (te TestEvent) Disposable() bool {
|
||||
return te.Dispose
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue