batch processor/scheduler configuration/setup help?

Hi everyone,

I’m still having some trouble setting up a batch processor. headless client. I’m hoping someone can point me in the right direction.

I need to run a script that sends out automated emails every 1/2 hour(depending on the search criteria). My script looks something like this:

plugins.scheduler.addCronJob(‘30mins’,‘0 0/2 * * * ?’, globals.emails_all)

i then went to the web-admin and added my solution. (I didn’t enter anything in arguments since i’m not sure what to enter).

The main problem is that when it’s running, all the clients get the “script” effect too. If the script finds no records, then all of sudden, the client that’s log into solution all of a sudden shows 0 records. Am i doing something wrong? Can someone enlighten me on this?

thanks,
sammy

Using Servoy version 3.1.3-build 407, repository version 29
java.vm.version=1.5.0_06-b05

Hi Sammy,

Your clients see the effect because the method is also scheduled in their client.

What you need to do is to let the scheduling method know it is called from the batchprocessor.
The argument property is exactly what you need for this.
Your scheduling method will look something like this:

var bIsBatchProcessor = arguments[0];

if ( bIsBatchProcessor )
{
  plugins.scheduler.addCronJob('30mins','0 0/2 * * * ?', globals.emails_all);
}

Now launch the solution as a batchprocessor and give it the parameter ‘true’ (no quotes).
That’s all.

Hope this helps.

Maybe can be a good idea to create a micro-application whose only objective is to schedule your mail process. Set this application as “module” so it is not shown with the normal application selection and start it in the servoy-admin as a batch process. Works fine for me. Of course you can also use this application to schedule or invoke other batch tasks.

Enrico’s suggestion is the best approach when you can.

I have created a batch processor module as well.
Issue was that I needed much of the functionality of the ‘main’ solution though.
It was a no-brainer that I was not going to redo the job so I decided to use that ‘main’ solution as a module.
Works like a charm and it give me more control and less ‘spaghetti’ coding than integrating both in one solution.

ROCLASI:
Hi Sammy,

Your clients see the effect because the method is also scheduled in their client.

What you need to do is to let the scheduling method know it is called from the batchprocessor.
The argument property is exactly what you need for this.
Your scheduling method will look something like this:

var bIsBatchProcessor = arguments[0];

if ( bIsBatchProcessor )
{
plugins.scheduler.addCronJob(‘30mins’,‘0 0/2 * * * ?’, globals.emails_all);
}




Now launch the solution as a batchprocessor and give it the parameter 'true' (no quotes).
That's all.


Hope this helps.

I just got a chance to work on this again. All my script has to do is send out an email when a new record is created in Servoy. I tried running this on developer. I followed exactly what you said putting launch batchprocessor parameter as true (no quotes). However, after I create a new record, no email gets sent. My email server is runing because if i run the email new record script manually, it works just fine. I reduced the interval to 2 minutes…still nothing. Anything else i’m doing wrong?

here’s my search script>

forms.admin_capa.controller.find()
forms.admin_capa.a_capa_opened_notified = ‘no’
var found = forms.admin_capa.controller.search()

for (var n = 1; n <= found; n++ )
{
forms.admin_capa.controller.recordIndex = n;
var to = ‘szheng1@ndcus.jnj.com’ //change to Maritza later , keyword bauer
var from = ‘ndc_fmodbc1@ndcus.jnj.com
var subject = ‘A new CAPA , CAPA # ’ + forms.admin_capa.main_capa_num + ’ has just been opened’
var msgText =‘A new CAPA, CAPA # ’ + forms.admin_capa.main_capa_num + ’ has just been opened. Please log into Servoy CAPA system to find out more details.’
plugins.mail.sendMail( to, from, subject, msgText)
forms.admin_capa.a_capa_opened_notified = ‘yes’
application.sleep(1000)

}

here’s my scheduler script>
var bIsBatchProcessor = arguments[0];

if ( bIsBatchProcessor )
{
plugins.scheduler.addCronJob(‘2mins’,‘0 0/2 * * * ?’, globals.emails_all);
}

am i doing something wrong.
thanks again for your help

Hi Sammy,

I guess we can assume the method works so lets concentrate on the scheduler.
One thing you have to know, you can only add a schedule with the same name once. So if you want to reset it you need to remove it first.
So the code would look like this.

var bIsBatchProcessor = arguments[0]; 

if ( bIsBatchProcessor ) 
{ 
  plugins.scheduler.removeJob('30mins');
  plugins.scheduler.addCronJob('30mins','0 0/2 * * * ?', globals.emails_all); 
}

Now load the batchprocessor and keep an eye on the server log for errors and ‘User idle since’ times under the Client page . It should show activity every 2 minutes.
If it doesn’t then you know it isn’t running.
Also putting application.output() functions in the code might help tracking what’s going on. This out shows up in the serverlog.
Like so:

var bIsBatchProcessor = arguments[0]; 

if ( bIsBatchProcessor ) 
{ 
  application.output('Scheduling 30mins method');
  plugins.scheduler.removeJob('30mins');
  plugins.scheduler.addCronJob('30mins','0 0/2 * * * ?', globals.emails_all); 
}

Hope this helps.

Robert,

thanks for your continual help in this problem. The updated code you gave me still didn’t work. The headless client remains idle. I also don’t see anything in the server log. (thru the web-admin) Am I looking in the right place?

However, i went back to my original code which is just one single line

plugins.scheduler.addCronJob(‘30mins’,‘0 0/2 * * * ?’, globals.emails_all)

And the emails are working fine. However, this brings me to the original problem of all the clients are see the “script” effect too.

This is so odd.
Well you could make it so it only runs in a headless client (which what the batchprocessor is) with the following code.

if ( application.getApplicationType() == 4 ) // Headless Client
{ 
  application.output('Scheduling 30mins method'); 
  plugins.scheduler.removeJob('30mins'); 
  plugins.scheduler.addCronJob('30mins','0 0/2 * * * ?', globals.emails_all); 
}

Of course when you want to use a headless client for webbased stuff then you have the same issues as with the rich client again.

Hope this helps.

ROCLASI:
This is so odd.
Well you could make it so it only runs in a headless client (which what the batchprocessor is) with the following code.

if ( application.getApplicationType() == 4 ) // Headless Client

{
application.output(‘Scheduling 30mins method’);
plugins.scheduler.removeJob(‘30mins’);
plugins.scheduler.addCronJob(‘30mins’,‘0 0/2 * * * ?’, globals.emails_all);
}




Of course when you want to use a headless client for webbased stuff then you have the same issues as with the rich client again.

Hope this helps.

it’s working perfectly now. Thanks again for your help Robert!!!

I’m new at the batch thing.
I’m trying to test a scheduled job to run every minute.
i made a separate module for the batch process.
Here’s my call to add the cron job:

plugins.scheduler.addCronJob(‘Sample_Followup’,‘0 0/60 * * * ?’,gm_sample_followup);

It is not currently working.
I also tried this:
plugins.scheduler.addCronJob(‘Sample_Followup’,‘* * * * * ?’,gm_sample_followup);

But then i get the emails like every second…
It seems like this timing format is different from the normal operating system crontab format.
What does the ? mean?
Is there better documentation on how to format this thing?
Thanks

Jason Meunier did a webinar today about it, I suppose it has been recorded, so check it out:
http://forum.servoy.com/viewtopic.php?f=26&t=13666

He posted a link to the Quartz cron syntax (Quartz is the Java Open Source library that Servoy is using in its scheduler plugin).
Check: http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

Thank you so very much!
This Quatz link was exactly what I was looking for.
For some reason in Servoy Developer, the sample code points to an invalid web URL.
That’s why I didn’t have this info.
Thank again.

i updated the url in the scheduler sample code.