4.1.3 Problems with scheduler.addCronJob

Hi,
im trying to add a cronJob using the scheduler plugin and after some research i found that to add one that calls a method with arguments i have to do this:

plugins.scheduler.addCronJob(‘name’,‘0/10 * * * * ?’,globals.methodName,new Array(arg1,arg2))

and in the global method declaration
var a1 = arguments[0];
var a2 = arguments[1];

but when i execute this i get this error
Can’t find method com.servoy.extensions.plugins.scheduler.SchedulerProvider.js_addCronJob(string,string,function,[Ljava.lang.Object;).

and i know the problem is with the Array because if i take it away, this gives me no error
Any idea of how can i solve this??

thanks in advance

You are omitting 2 parameters so you need to use nulls to be able to specify the last one:

plugins.scheduler.addCronJob(jobname, cronTimings, Function globalMethod, [Date startDate], [Date endDate], [Object[] arguments])

plugins.scheduler.addCronJob('name','0/10 * * * * ?',globals.methodName,null,null,new Array(arg1,arg2))

Now… why didnt i think about that??
Thanks a lot nicola that solved my problem

Sometimes the most evident mistakes are the hardest to spot, keep in mind that anytime you see an error like “Can’t find method XYZ params(a,b,c)” you are passing wrong parameters to it.
Another error message that really helps to debug is something like “xxx.yyy: nullpointer”, where xxx is an object and yyy a property, it means that you are trying to touch a property of a null object.

I have a new problem with this now, i recently realized that when i run my application on my admin profile it works fine but if i run it on a different profile for some reason the scheduled job wont work. This makes me think that maybe the scheduler is starting some kind of service on my OS or something like that and perhaps my firewall or something is preventing it from work. Any idea of what could this be??
thanks

Hi,

I also have a problem with scheduler.addCronJob. I’ve not yet reach your point as I have the “Can’t find method” error.
I use the database to store my jobs settings and here is the code I use to add a job:

var jobCreated = plugins.scheduler.addCronJob(fld_job_name, fld_cron_timings, fld_methodname,null,null,null)

I’m getting this error:

Can’t find method com.servoy.extensions.plugins.scheduler.SchedulerProvider.js_addCronJob(string,string,string,null,null,null). (startJobInScheduler#3)

I have looked at the sample code provided in developer:

	// see: http://quartz.sourceforge.net/firstTutorial.html#cronTriggers for more info
	// add a job that runs every 20 minutes after the hour (0,20,40)
	plugins.scheduler.addCronJob('20mins','0 0/20 * * * ?',globalMethod)
	// add a job that runs every day at 23:30 between now and 5 days from now
	var dateNow = new Date();
	var date5Days = new Date(dateNow.getTime()+5*24*60*60*1000);
	plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',globalMethod,dateNow,date5Days)

But even with the same number and type of parameter than is this example I get the error:

Can’t find method com.servoy.extensions.plugins.scheduler.SchedulerProvider.js_addCronJob(string,string,string). (startJobInScheduler#3)

I use also Servoy 4.1.3 (build 672) and the batch user is in the Users group only (not Administrator)
Any idea?

Foobrother:

plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',globalMethod,dateNow,date5Days)

Can’t find method com.servoy.extensions.plugins.scheduler.SchedulerProvider.js_addCronJob(string,string,string). (startJobInScheduler#3)

What is “globalMethod”? A var containing a string I guess.
That’s the problem: you need to pass a function, not a string. Try this:

plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',globals.myGlobalMethod,dateNow,date5Days)

Beware: do not put brackets after the global method name, ex.: globals.myGlobalMethod(), otherwise it will be executed straight ahead.

ngervasi:
What is “globalMethod”? A var containing a string I guess.
That’s the problem: you need to pass a function, not a string. Try this:

plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',globals.myGlobalMethod,dateNow,date5Days)

Beware: do not put brackets after the global method name, ex.: globals.myGlobalMethod(), otherwise it will be executed straight ahead.

You are right! It was because of the method. As I have the method name stored in the database I had to use this code:

var jobCreated = plugins.scheduler.addCronJob(fld_job_name, fld_cron_timings, globals[fld_methodname])

Now it works :D
Thanks.

To come back to nromeou last issue, in my case I use a user which is not administrator on Servoy and also not a Windows user. However Servoy Server service runs on an Administrator account.