Background Tasks

From Lianjapedia
Revision as of 05:22, 2 May 2018 by Barrymavin (Talk | contribs)

Jump to: navigation, search

Under construction

It is a common requirement to be able to schedule the running of background scripts.

Since Lianja 4.1.2 you can run background scripts written in Lianja/VFP, Python, PHP and/or JavaScript by specifying command options to the lianja or lianjaruntime commands.

These scripts run independently of the GUI but have full access to the Lianja Framework (GUI and non-GUI) including the database and Recordset classes.

This provides the ability to run scripts from cron on linux or task scheduler on windows.

Linux cron: https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html

Windows Task Scheduler: https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx

You specify the input file using the -i(--input) command line switch and the output file using the -o(--output) command line switch.

It is trivial to generate an HTML report and email that to someone using the Amazon AWS Simple Email service if you have an AWS account. https://aws.amazon.com/ses/pricing/

Example:

Run a Lianja/VFP script in the current directory.

lianja -i myscript.dbo -o myreport.html

Run a python script in the lianjademo app.

lianja -i app:/lianjademo/lianjademo_pythondb.py -o myreport.html

Run a PHP script in the lianjademo app.

lianja -i app:/lianjademo/lianjademo_phpdb.php -o myreport.html

Run a JavaScript script in the lianjademo app.

lianja -i app:/lianjademo/lianjademo_javascriptdb.js -o myreport.html

Notice that these examples will access the development directories as they run lianja. If you want to access the runtime directories use the lianjaruntime command.

You can find a full list of command line switches in the doc. https://www.lianja.com/doc/index.php/Command_Line_Switches

You can perform database admin tasks from the console or in background scripts.

The -c(--command) command line switch allows multiple commands to be concatenated into a script.

# lianja -c "open database southwind;select top 5 customerid,contactname,companyname\
 from customers"
 CUSTOMERID CONTACTNAME                    COMPANYNAME                             
 ALFKI      Maria Anders                   Alfreds Futterkiste
 ANATR      Ana Trujillo                   Ana Trujillo Emparedado
 AROUT      Thomas Hardy                   Around the Horn again
 BERGS      Christina Berglund             Berglunds snabbkop
 BLAUS      Hannah Moos                    Bill's furniture store
5 records selected in <1ms
# lianja -c "backup database southwind;"
# lianja -c "optimize database southwind;"

All command line switches can be found here: https://www.lianja.com/doc/index.php/Command_Line_Switches

If required you can redirect output using the -o switch.

# lianja -c "open database southwind;select top 5 customerid,contactname,companyname \
from customers" -o mydata.txt