go-co-op / gocron

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
MIT License
5.7k stars 308 forks source link

[BUG] - Cannot create job with task with variadic args #677

Closed bbompk closed 4 months ago

bbompk commented 9 months ago

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:

  1. Create a function that has variadic args
  2. 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

bbompk commented 9 months ago

Well I guess I should use slice as an argument instead of variadic args..

JohnRoesler commented 9 months ago

That's an option. But may be a way to handle variadic args.

Higan commented 4 months ago

Hi @JohnRoesler I just created a PR https://github.com/go-co-op/gocron/pull/755 to resolve this issue.

JohnRoesler commented 4 months ago

Thanks @Higan 👏