gocron
gocron copied to clipboard
[BUG] - Cannot create job with task with variadic args
Describe the bug
When creating a job with a task that has variadic args, the validator in the library will expect the variadic args to be "1" argument (suspect to be a slice of that type). So creating a job with a task that has function of variadic arguments will always return ErrNewJobWrongNumberOfParameters.
To Reproduce
Steps to reproduce the behavior:
- Create a function that has variadic args
- Try create a cronjob from that
scheduler, _ := gocron.NewScheduler()
myfunc := func(args ...string) {
panic("This works")
}
// will have error
job, err := scheduler.NewJob(
gocron.CronJob("* * * * 1", false),
gocron.NewTask(myfunc), // the validator will expect num param to be 1 (slice of string)
)
Version
v2.2.1
Expected behavior
should be able to execute task with variadic parameters.
Additional context
Well I guess I should use slice as an argument instead of variadic args..
That's an option. But may be a way to handle variadic args.
Hi @JohnRoesler I just created a PR https://github.com/go-co-op/gocron/pull/755 to resolve this issue.
Thanks @Higan 👏