gocron icon indicating copy to clipboard operation
gocron copied to clipboard

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

Open bbompk opened this issue 1 year ago • 2 comments

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 avatar Feb 23 '24 02:02 bbompk

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

bbompk avatar Feb 23 '24 02:02 bbompk

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

JohnRoesler avatar Feb 23 '24 03:02 JohnRoesler

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

Higan avatar Jul 11 '24 13:07 Higan

Thanks @Higan 👏

JohnRoesler avatar Jul 11 '24 18:07 JohnRoesler