Skip to content

Commit

Permalink
chore(timers): one time schedule all timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Dec 17, 2023
1 parent 3f11581 commit 7616ac1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/timers/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/satont/twir/apps/timers/internal/repositories/channels"
"github.com/satont/twir/apps/timers/internal/repositories/streams"
"github.com/satont/twir/apps/timers/internal/repositories/timers"
"github.com/satont/twir/apps/timers/internal/s"
"github.com/satont/twir/apps/timers/internal/worker"
"github.com/satont/twir/apps/timers/internal/workflow"
cfg "github.com/satont/twir/libs/config"
Expand Down Expand Up @@ -43,6 +44,7 @@ func main() {
),
fx.NopLogger,
fx.Invoke(
s.New,
worker.New,
grpc_server.New,
func(l logger.Logger) {
Expand Down
19 changes: 19 additions & 0 deletions apps/timers/internal/s/s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package s

import (
"context"

"github.com/satont/twir/apps/timers/internal/repositories/timers"
"github.com/satont/twir/apps/timers/internal/workflow"
)

func New(repository timers.Repository, w *workflow.Workflow) {
timers, err := repository.GetAll()
if err != nil {
return
}

for _, timer := range timers {
w.AddTimer(context.TODO(), timer.ID)
}
}
2 changes: 1 addition & 1 deletion apps/timers/internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func New(opts Opts) error {
if err != nil {
return err
}

temporalWorker := worker.New(c, shared.TimersWorkerTaskQueueName, worker.Options{})

temporalWorker.RegisterWorkflow(opts.Workflow.Flow)
Expand Down

0 comments on commit 7616ac1

Please sign in to comment.