coravel icon indicating copy to clipboard operation
coravel copied to clipboard

Adding a new overloaded method ScheduleWithParams which takes Type as an input

Open karthikveeraj opened this issue 3 years ago • 0 comments

Problem The existing IScheduler interface has ScheduleWithParams<T> method which supports only generic type parameter. We create different jobs and store job-related information in the database (this includes className and AssemblyName). When I try to load such jobs dynamically, the existing interface does not allow it.

For example: Let's say I have a job called PeriodicEmailer. The existing solution : scheduler.ScheduleWithParams<PeriodicEmailer>(param1, param2).

In my case I get the Type information from different sources (config file or database). I would like to perform the same like below:

var jobType = Type.GetType("mynamespace.PeriodicEmailer, myassembly");
scheduler.ScheduleWithParams(jobType , param1, param2);

Alternatives Currently, I'm running a bunch of if else conditions like below:

if(jobType .Name == "PeriodicEmailer") 
{
  scheduler.ScheduleWithParams<PeriodicEmailer>(param1, param2)
}
else if(jobType .Name == "MyJob2") 
{
  scheduler.ScheduleWithParams<MyJob2>(param1, param2)
}

Having a new method ScheduleWithParams(Type invocableType, params object[ ] parameters); I'm moving from Quartz to Coravel. I really appreciate it a lot if you guys allow me to enable this feature. I already worked on this. I need a ticket to raise PR for this.

karthikveeraj avatar Jun 07 '21 03:06 karthikveeraj