Custom scheduler with parameters

Note: Please do not suggest third party tools for this, I am not interested in purchasing any.

I am a Sugar customer with an On-Site 10.x Sugar Pro license.

I have a custom Scheduled Job for which the parameters change year after year.

Though I know how to trigger an ad-hoc scheduler with parameters from, say, a Logic Hook, I am looking for a way to set the Parameters at the time it is Scheduled.

In other words I want to run the Scheduler with parameters A, B at certain times, and with parameters C, D at other times, where those parameters and the frequency of the scheduler change year by year or month by month.

I'd really like to be able to have a non-developer/non-technical Sugar Admin be able to change the Scheduler to Active, set the timing for the scheduler to run, AND set the Event Code for that scheduler. 

This is the simplified scenario: We host a number of events every year. Our custom modules link registrations to the Event. Our Events Organization staff has no need to be in Sugar, but they want to receive a regularly scheduled report of registrations. Using a Sugar Report is not an option, we only have Sugar Pro and this is too complex for the kind of reporting we have access to, besides, I could not schedule the report for people who do not have a Sugar account.

Of course I can do this by hardcoding the Event Code in the Scheduler and using MailerFactory to email the report to their group email, it is what I've been doing. But every time there is a new event I have to edit the Scheduler's code and change the Event Code.

This also means that I can't, for example, schedule the emails for one event to be weekly and for another to be daily unless I write multiple schedulers... etc... 

Sure, I can build an API with params for this and an interface for them to run it ad-hoc, and I have, but they want a scheduled email.
I could build a mailer that runs the API with params, but again I have to be the one setting those params in the mailer, so I'm just rebuilding a "Scheduler"

I could build another module where our non-developer/non-technical Sugar Admins can pick the scheduler name, params, and start/end date for that scheduler, pick a frequency, then query that module to pick the parameters to be used... but the more I think about it the more it feels like reinventing the wheel... and should I really be building a scheduler for schedulers?! Thinking


Could I customize the scheduler module? Maybe...

So this more of a "what would you do" kind of question for those with more experience than me...


Any thoughts on what you would do? Slight smile

Thanks,
FrancescaS

Parents
  • Hi Francesca!

    You could create a Scheduler Job using your logic hook (or other mechanism) and then attach your parameters for that run via the "data" attribute. When the job that you scheduled executes, your custom job code will receive that "data" attribute and you can then use those values for whatever you want within that execution.

    Hope that helps!

  • Right, I know I can do that, but that's still hardcoding the parameters.

    I want to schedule the same report multiple times so I can schedule for the next three months for Event 1, and the same report for the next two weeks for Event 2 etc... where the event is specified as a parameter passed when I schedule it, not in code. Does that make sense?

  • I'm afraid you are talking about a custom scheduler engine. Core Schedulers module, as a BWC one, is not a good target of customizations.

    I can imagine a custom module called "Event Scheduler" which has some fields which fit those parameters you mentioned.

    By saving a record of Event Scheduler it will save an entry into job_queue table according to the parameters you just configured.

    The record from job_queue reffers to a custom class which knows how to acquire and parse the paramters, so it can compile the report and email to targets accordingly.

    From that moment cron.php will do the job for you.

    Good luck

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Thank you!


    I was afraid that might be the only solution.

    For the time being I only have to change it once a year, so I'll stick to code changes. 

    If it gets more complicated I'll see if it's worth doing a custom Scheduler.

Reply Children
No Data