Difference between revisions of "Background Tasks"

From Lianjapedia
Jump to: navigation, search
 
(36 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''Under construction''
+
It is a common requirement to be able to schedule the running of background scripts.
  
It is a common requirement to be able to schedule the running of background scripts.
+
Typical uses of background scripts are the loading of data from external data sources, generating and emailing HTML reports, periodic database admin, data consolidation and analysis and much more.
  
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.
+
You can run background scripts written in Lianja/VFP, Python, PHP and/or JavaScript by specifying command line options to the '''lianjarun''' command.
  
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.
+
These scripts run independently of Lianja  but have full access to the [[:Category:Framework_Classes|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.
+
This provides the ability to schedule the running of scripts using  cron on linux, task scheduler on windows or launchd on macOS.
  
Linux cron:
+
[https://www.redhat.com/sysadmin/automate-linux-tasks-cron 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 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.
+
[https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/ScheduledJobs.html macOS launchd]
  
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.
+
==--input and --output==
https://aws.amazon.com/ses/pricing/
+
You specify the input file using the -i (--input) command line switch and the output file using the -o (--output) command line switch.
  
Example:
+
You can, for example,  generate an HTML report and email that to someone using the [https://aws.amazon.com/ses/pricing/ Amazon AWS Simple Email Service] if you have an AWS account.
 +
 
 +
'''Examples:'''
  
 
Run a Lianja/VFP script in the current directory.
 
Run a Lianja/VFP script in the current directory.
  
 
<pre>
 
<pre>
lianja -i myscript.dbo -o myreport.html
+
lianjarun -i myscript.dbo -o myreport.html
 
</pre>
 
</pre>
  
Line 31: Line 31:
  
 
<pre>
 
<pre>
lianja -i app:/lianjademo/lianjademo_pythondb.py -o myreport.html
+
lianjarun -i app:/lianjademo/lianjademo_pythondb.py -o myreport.html
 
</pre>
 
</pre>
  
Line 37: Line 37:
  
 
<pre>
 
<pre>
lianja -i app:/lianjademo/lianjademo_phpdb.php -o myreport.html
+
lianjarun -i app:/lianjademo/lianjademo_phpdb.php -o myreport.html
 
</pre>
 
</pre>
  
Line 43: Line 43:
  
 
<pre>
 
<pre>
lianja -i app:/lianjademo/lianjademo_javascriptdb.js -o myreport.html
+
lianjarun -i app:/lianjademo/lianjademo_javascriptdb.js -o myreport.html
 
</pre>
 
</pre>
  
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.
+
Notice that these examples will access the development directories as they run '''lianjarun'''. If you want to access the runtime directories use the '''lianjarun''' command with the --runtime command line switch [[#--runtime|as shown below]].
  
You can find a full list of command line switches in the doc.
+
You can find a full list of [[Command_Line_Switches|command line switches here.]]
https://www.lianja.com/doc/index.php/Command_Line_Switches
+
  
You can  perform database admin tasks from the console or in background scripts.
+
You can  perform [[:Category:Databases|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.
+
==--command==
 +
The -c (--command) command line switch allows multiple commands to be concatenated into a script. Each line should be separated with a semi colon and no block statements are supported e.g if, for, do while etc.
  
 
<pre>
 
<pre>
# lianja -c "open database southwind;select top 5 customerid,contactname,companyname\
+
lianjarun -c "open database southwind;select top 5 customerid,contactname,companyname \
from customers"
+
from customers"
 
  CUSTOMERID CONTACTNAME                    COMPANYNAME                             
 
  CUSTOMERID CONTACTNAME                    COMPANYNAME                             
 
  ALFKI      Maria Anders                  Alfreds Futterkiste
 
  ALFKI      Maria Anders                  Alfreds Futterkiste
Line 65: Line 65:
 
  BLAUS      Hannah Moos                    Bill's furniture store
 
  BLAUS      Hannah Moos                    Bill's furniture store
 
5 records selected in <1ms
 
5 records selected in <1ms
# lianja -c "backup database southwind;"
+
lianja -c "backup database southwind;"
# lianja -c "optimize database southwind;"
+
lianja -c "optimize database southwind;"
 
</pre>
 
</pre>
 
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.
 
If required you can redirect output using the -o switch.
  
 
<pre>
 
<pre>
# lianja -c "open database southwind;select top 5 customerid,contactname,companyname \
+
lianjarun -c "open database southwind;select top 5 customerid,contactname,companyname \
 
from customers" -o mydata.txt
 
from customers" -o mydata.txt
 
</pre>
 
</pre>
 +
 +
==--runtime==
 +
If --runtime is specified, the commands operate against the runtime/deployed data and files, otherwise they operate within the context of the App Builder.
 +
<pre>lianjarun --runtime -c "select top 5 customerid,contactname,companyname \
 +
from southwind!customers"</pre>
 +
 +
<pre>lianjarun --runtime -i lib:/myscript.dbo -o myoutput.txt</pre>
 +
 +
[[Category:Lianja v4.2]]
 +
[[Category:Lianja v5.3]]
 +
[[Category:Lianja v6.0]]

Latest revision as of 10:32, 20 February 2023

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

Typical uses of background scripts are the loading of data from external data sources, generating and emailing HTML reports, periodic database admin, data consolidation and analysis and much more.

You can run background scripts written in Lianja/VFP, Python, PHP and/or JavaScript by specifying command line options to the lianjarun command.

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

This provides the ability to schedule the running of scripts using cron on linux, task scheduler on windows or launchd on macOS.

Linux cron

Windows Task Scheduler

macOS launchd

--input and --output

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

You can, for example, generate an HTML report and email that to someone using the Amazon AWS Simple Email Service if you have an AWS account.

Examples:

Run a Lianja/VFP script in the current directory.

lianjarun -i myscript.dbo -o myreport.html

Run a python script in the lianjademo app.

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

Run a PHP script in the lianjademo app.

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

Run a JavaScript script in the lianjademo app.

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

Notice that these examples will access the development directories as they run lianjarun. If you want to access the runtime directories use the lianjarun command with the --runtime command line switch as shown below.

You can find a full list of command line switches here.

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

--command

The -c (--command) command line switch allows multiple commands to be concatenated into a script. Each line should be separated with a semi colon and no block statements are supported e.g if, for, do while etc.

lianjarun -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;"

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

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

--runtime

If --runtime is specified, the commands operate against the runtime/deployed data and files, otherwise they operate within the context of the App Builder.

lianjarun --runtime -c "select top 5 customerid,contactname,companyname \
from southwind!customers"
lianjarun --runtime -i lib:/myscript.dbo -o myoutput.txt