1
0

event.go 891 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package model
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/710leo/urlooker/dataobj"
  6. . "github.com/710leo/urlooker/modules/web/store"
  7. )
  8. type Event dataobj.Event
  9. var EventRepo *Event
  10. func (this *Event) Insert() error {
  11. _, err := Orm.Insert(this)
  12. return err
  13. }
  14. func (this *Event) GetByStrategyId(strategyId int64, before int) ([]*Event, error) {
  15. events := make([]*Event, 0)
  16. ts := time.Now().Unix() - int64(before)
  17. err := Orm.Where("strategy_id = ? and event_time > ?", strategyId, ts).Desc("event_time").Find(&events)
  18. return events, err
  19. }
  20. func (this *Event) String() string {
  21. return fmt.Sprintf(
  22. "<Id:%s, EventId:,%s Ip:%s, Url:%s, EventTime:%v, StrategyId:%d, RespTime:%s, RespCode:%s, Status:%s, (%d/%d)>",
  23. this.Id,
  24. this.EventId,
  25. this.Ip,
  26. this.Url,
  27. this.EventTime,
  28. this.StrategyId,
  29. this.RespTime,
  30. this.RespCode,
  31. this.Status,
  32. this.CurrentStep,
  33. this.MaxStep,
  34. )
  35. }