Added Fiber and layouts
This commit is contained in:
parent
f8e7ea482b
commit
63b19a249a
17 changed files with 331 additions and 37 deletions
38
services/jobs/services.go
Normal file
38
services/jobs/services.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lmika.dev/lmika/hugo-crm/models"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
queue chan models.Job
|
||||
}
|
||||
|
||||
func New() *Service {
|
||||
return &Service{
|
||||
queue: make(chan models.Job, 50),
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Service) Start() {
|
||||
go func() {
|
||||
for j := range j.queue {
|
||||
if err := j.Do(context.Background()); err != nil {
|
||||
log.Printf("job failed %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (j *Service) Stop() {
|
||||
q := j.queue
|
||||
j.queue = nil
|
||||
close(q)
|
||||
}
|
||||
|
||||
func (j *Service) Queue(ctx context.Context, job models.Job) error {
|
||||
j.queue <- job
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue