You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
908 B
47 lines
908 B
package service |
|
|
|
import ( |
|
"context" |
|
"sync" |
|
|
|
"go-common/app/job/main/appstatic/conf" |
|
"go-common/app/job/main/appstatic/dao/caldiff" |
|
"go-common/app/job/main/appstatic/dao/push" |
|
"go-common/library/log" |
|
) |
|
|
|
var ctx = context.Background() |
|
|
|
// Service . |
|
type Service struct { |
|
c *conf.Config |
|
dao *caldiff.Dao |
|
pushDao *push.Dao |
|
waiter *sync.WaitGroup |
|
daoClosed bool |
|
} |
|
|
|
// New creates a Service instance. |
|
func New(c *conf.Config) (s *Service) { |
|
s = &Service{ |
|
c: c, |
|
dao: caldiff.New(c), |
|
pushDao: push.New(c), |
|
waiter: new(sync.WaitGroup), |
|
} |
|
s.waiter.Add(1) |
|
go s.pushproc() |
|
s.waiter.Add(1) |
|
go s.calDiffproc() |
|
return |
|
} |
|
|
|
// Close releases resources which owned by the Service instance. |
|
func (s *Service) Close() (err error) { |
|
log.Info("Close dao!") |
|
s.daoClosed = true |
|
log.Info("Wait waiter!") |
|
s.waiter.Wait() |
|
log.Info("appstatic-job has been closed.") |
|
return |
|
}
|
|
|