-
Hello, thanks for the work Do you know how to provide a dependency throw fx uber regards |
Beta Was this translation helpful? Give feedback.
Answered by
reugn
Dec 25, 2024
Replies: 1 comment
-
One of the options is to create a service to instantiate job details. package main
import (
"context"
"fmt"
"log"
"github.com/reugn/go-quartz/job"
"github.com/reugn/go-quartz/quartz"
"go.uber.org/fx"
)
type JobDetailService struct {
Job quartz.Job
}
func (s *JobDetailService) NewJobDetail(jobKey *quartz.JobKey) *quartz.JobDetail {
return quartz.NewJobDetail(s.Job, jobKey)
}
func NewJobDetailService(job quartz.Job) *JobDetailService {
return &JobDetailService{Job: job}
}
func main() {
app := fx.New(
fx.Options(
fx.Provide(func() quartz.Job {
return job.NewFunctionJobWithDesc(
"job1",
func(ctx context.Context) (string, error) { return "ok", nil },
)
}),
fx.Provide(NewJobDetailService),
),
fx.Invoke(func(s *JobDetailService) {
detail := s.NewJobDetail(quartz.NewJobKey("key1"))
fmt.Printf("%s - %s\n", detail.JobKey().String(), detail.Job().Description())
}),
)
ctx := context.Background()
if err := app.Start(ctx); err != nil {
log.Fatal(err)
}
defer app.Stop(ctx)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
7amou3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One of the options is to create a service to instantiate job details.