Batch processors

At the moment, the server is working on Windows. But this method have to work with Linux and Mac OS/X.

In first, I wanted to create a stored procedure in PostgreSQL and executed it from servoy. But Postres don’t allow to create Procedure, only function. Unfortunately I can’t execute a REINDEX, PG_DUMP OR VACUUM command on database in function because “REINDEX cannot be executed inside a transaction block.
http://www.postgresql.org/docs/8.2/inte … index.html

So I choosed to use cronjob. I created a Startup script :

var jobname = “backup”
var cronTimings = “* 00 22 * * ?”
var startDate = new Date()
var endDate = new Date(startDate.getFullYear()+50,startDate.getMonth(),startDate.getDate())
var args = new Array(directory_postgres,directory_for_backup)

plugins.scheduler.addCronJob(jobname, cronTimings, globals.Backup_DB,startDate,endDate,args)

The method backup:

var directory_postgres = arguments[0]
var directory_for_backup= arguments[1]

//Returns the name of the operating system
var osname = application.getOSName();

if(osname.indexOf(“Windows”,0)>-1){

var file = plugins.file.convertToJSFile(directory_postgres +“/vacuumdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/vacuumdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”)

var file = plugins.file.convertToJSFile(directory_postgres +“/reindexdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/reindexdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”

var file = plugins.file.convertToJSFile(directory_postgres +“/pg_dump.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/pg_dump.exe”,“-i”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-F”,“t”,“-f”,“"“directory_for_backup+”/database_save.backup"”,“sopavet”

}

I have to add security rules with postgres’s user and complete this method for Linux and Mac OS/X.

It’s work fine on Windows XP with Postgres 8.1, but I didn’t know that batch process use one client license :shock:.So I have to find another way to backup my database.

but I didn’t know that batch process use one client license .So I have to find another way to backup my database.

But doesn’t the cost of one client weight up to the ease of use (as you said yourself)?
Obviously I don’t do any sales for Servoy but imho you can create a fully customizable tool against a low price.

But doesn’t the cost of one client weight up to the ease of use (as you said yourself)?

hehe :wink:

I will try to convince my boss :)

Hi Marcel

Yes we looked at animated GIFs but new Images are being added to the Artists database all the time and to be fair to everyone the GIFs have to be selected at random.

Now looking at grabbing say 50 at a time into a Media array (each GIF is only 40-50kb) then just selecting from that array rather than going back to the DB each time.

Graham Greensall
Worxinfo Ltd

I have a last question about batch processors.

Can I start / Stop / Add or remove a batch processor on Servoy’server in a method (With scheduler plugin for example)?

Thanks to that, I be able to start a Headless client without the webadmin and it will be completely transparent for the user.

thanks

The answer is no, so far I know.

Why would you btw, let it run :)

There are no functions available to add batch processors other than manually through the admin pages.

But you could offcourse have a batchprocessor that runs multiple processes sequentially, based on configuration records that you store in a table.

That batchprocessor could also determine to start a certain process or not based on a value (read: status) in a certain column of the config records.

Paul

Actually the answer is yes, with some work you can.

First of all you can remove cronjobs with a method.
The only thing you need to do is setup a table where you manage your cronjobs (records) together with a cronjob that periodically reads this table and checks for changes.
When a cronjob record has changed it removes the running cronjob and reapplies it with the new settings.
When a cronjob record was removed (or marked as such) it simply removes the cronjob.

So it all will be data driven.

Hope this helps.

Ah, I should read better before I reply.
No indeed you can’t add batchprocessors via a cronjob. BUT you can use 1 single batchprocessor and use the technique I described in previous post.

Glad you saw it! Did not want to correct you again :lol:

Hehe :wink:

Oki thanks

IT2Be:
Glad you saw it! Did not want to correct you again :lol:

:stuck_out_tongue:

You were both too late… :twisted:

IT2Be:
The only thing you need to know/realize that this ‘eats’ one client license!

The licence is eaten always? Only when the headless client perform the cronjob or always when the headless client is started (in a production server = always)?

axterics:

IT2Be:
The only thing you need to know/realize that this ‘eats’ one client license!

The licence is eaten always? Only when the headless client perform the cronjob or always when the headless client is started (in a production server = always)?

Technically it is running at all times so yes it eats a license. You could overcome this by using external schedulers but unless you have a lot of free time (as in free beer) it’s more economical to buy a license.

The batchprocessor is fired up when the server starts and as long as it is alive (server down or manual quit via server pages) there is a client.
Which makes sense…

Pierre-andre:
At the moment, the server is working on Windows. But this method have to work with Linux and Mac OS/X.

In first, I wanted to create a stored procedure in PostgreSQL and executed it from servoy. But Postres don’t allow to create Procedure, only function. Unfortunately I can’t execute a REINDEX, PG_DUMP OR VACUUM command on database in function because “REINDEX cannot be executed inside a transaction block.
http://www.postgresql.org/docs/8.2/inte … index.html

So I choosed to use cronjob. I created a Startup script :

var jobname = “backup”
var cronTimings = “* 00 22 * * ?”
var startDate = new Date()
var endDate = new Date(startDate.getFullYear()+50,startDate.getMonth(),startDate.getDate())
var args = new Array(directory_postgres,directory_for_backup)

plugins.scheduler.addCronJob(jobname, cronTimings, globals.Backup_DB,startDate,endDate,args)

The method backup:

var directory_postgres = arguments[0]
var directory_for_backup= arguments[1]

//Returns the name of the operating system
var osname = application.getOSName();

if(osname.indexOf(“Windows”,0)>-1){

var file = plugins.file.convertToJSFile(directory_postgres +“/vacuumdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/vacuumdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”)

var file = plugins.file.convertToJSFile(directory_postgres +“/reindexdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/reindexdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”

var file = plugins.file.convertToJSFile(directory_postgres +“/pg_dump.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/pg_dump.exe”,“-i”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-F”,“t”,“-f”,“"“directory_for_backup+”/database_save.backup"”,“sopavet”

}

I have to add security rules with postgres’s user and complete this method for Linux and Mac OS/X.

It’s work fine on Windows XP with Postgres 8.1, but I didn’t know that batch process use one client license :shock:.So I have to find another way to backup my database.

I have the same requirement however i need to pass “where condition”(e.g. usderid=‘xyz’). I believe I cannot use pgdump. =( I would need to do it the hard way. Can you advice if my steps in doing the backup_db method is correct?

  1. acquire lock in the database during the process
  2. select all the tables
  3. for each table
    loadrecords
    for each record
    create the insert statement
    write in .sql file
  4. release the lock

thanks in advance.

Have you considered using pgAgent? Sounds like less work to me.

http://www.postgresonline.com/journal/a … ckups.html

Jan Aleman:
Have you considered using pgAgent? Sounds like less work to me.

http://www.postgresonline.com/journal/a … ckups.html

Thank you for the suggestion but I am not allowed to use other interface of other software application.