Generate Reports Automatically: Difference between revisions

From IHRIS Wiki
(Created page with "This tutorial shows you how to archive reports automatically. Please make sure you have enable the Report Archive module before proceeding. The first step is to determine the...")
 
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This tutorial shows you how to archive reports automatically.
This tutorial shows you how to generate reports automatically in the background with a [[Cron Jobs|cron job]].


Please make sure you have enable the Report Archive module before proceeding.
By default, iHRIS will launch automatically a background process to generate reports.  However, this may be less than ideal on systems with higher load or a larger number of records.  Instead, you may wish to schedule reports to be run at specific times.  For example:
*The search report should be run hourly -- this way new people added to the system will show up in the search page
*Other reports should be run on a nightly basis


The first step is to determine the list of reports that you want archived.  More precisely it is the report views that you want saved. You should also determien the frequency that you want them archive them on.  In this example, based on iHRIS Botswana,  we show you how to setup monthly archiving of selected reports.
The first step is to determine the list of reports that you want to generate.   You should also determine the frequency that you want them archive them on.  In this example, based on iHRIS Botswana,  we show you how to setup generation of hourly search reports and other reports nightly.


==Getting the Report Views==
==Turn Off Background Report Generation==
You should first create a list of the report views that you want to archive.  For each of the report views that you want you can get the name/index of the report view from the URLForm example, if the report you are interested is at:
See [[Configuring Report Generation Timing]].   
http://localhost/iHRIS-manage/CustomReports/show/facility_list
then the name of the report view is
facility_list


In the example below we will suppose our list of reports views we wish to archive are:
==Getting the Report Name==
facility_list 11238232 search_people
You should first create a list of the reports that you want to generate  For each of the report views that you want you can get the name/index of the report from the URL.  The easiest way to do this is go to  
 
*Configure System
Note: this saves the default "export" of the report, which is usually an spreadsheet.  So if you select a report view which is a graph, you will archive the underlying data rather than the graph itself.
*Reports
 
Now scroll over the "generate" link next to report that you are interested in with your mouse, and you should see a URL like:
==Creating A Shell Script==
  http://localhost/iHRIS/manage/CustomReports/generate/search_people
Then "search_people" is the name of the report.
==Creating A Shell Script (Hourly)==
In your site customizations, create a new top-level directory called "cron."  For example if you site is at:
In your site customizations, create a new top-level directory called "cron."  For example if you site is at:
  /var/lib/iHRIS/sites/mySite
  /var/lib/iHRIS/sites/mySite
Line 28: Line 30:
<source lang='bash'>
<source lang='bash'>
  cd /var/lib/iHRIS/sites/mySite/cron
  cd /var/lib/iHRIS/sites/mySite/cron
  gedit archive_reports.sh
  gedit generate_reports_hourly.sh
</source>
</source>
This will open up an editor.  You want to add the following:
This will open up an editor.  You want to add the following:
<source lang='bash'>
<source lang='bash'>
#!/bin/bash
#!/bin/bash
reports="facility_list 11238232 search_people"
reports="search_people"
for report in $reports  
for report in $reports  
do
do
     echo Archiving with /usr/bin/php ../pages/index.php --page=/CustomReports/archive/$report --nocheck=1
     echo Archiving with /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/$report --nocheck=1
     /usr/bin/php ../pages/index.php --page=/CustomReports/archive/$report --nocheck=1
     /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/$report --nocheck=1
done
done
</source>
</source>
then save and exit.  What this does is run through the list of report views (contained in the variable report) and archives them each individually
then save and exit.  What this does is run through the list of reports (contained in the variable report) and generate them each individually


See iHRIS Botswana for an [http://bazaar.launchpad.net/~ihris+botswana/ihris-manage/4.0/view/head:/cron/generate_reports_hourly.sh example].


==Creating A Shell Script (Nightly)==
In your site customizations, create a new top-level directory called "cron."  For example if you site is at:
/var/lib/iHRIS/sites/mySite
you can do:
<source lang='bash'>
cd /var/lib/iHRIS/sites/mySite
mkdir -p cron
</source>


See iHRIS Botswana for an [http://bazaar.launchpad.net/~ihris+botswana/ihris-manage/4.0/view/head:/cron/archive_reports.sh example].
Now we want to create a shell script that will archive '''all''' reports from the command line.  To do so:
<source lang='bash'>
cd /var/lib/iHRIS/sites/mySite/cron
gedit generate_reports_nighly.sh
</source>
This will open up an editor.  You want to add the following:
<source lang='bash'>
#!/bin/bash
do
    echo Archiving with /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/ --nocheck=1
    /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force --nocheck=1
done
</source>
then save and exit. This time, since we are generating all the reports, we did not need to list out each of the individual reports as the command will automatically try to generate them all.


==Committing to bzr (Optional)==
==Committing to bzr (Optional)==
Line 51: Line 75:
cd /var/lib/iHRIS/sites/mySite
cd /var/lib/iHRIS/sites/mySite
bzr add cron
bzr add cron
bzr commit -m "added shell script to handle archiving reports"
bzr commit -m "added shell script to handle generation of reports"
</source>
</source>


Line 62: Line 86:
which will open up gedit.  We want to add the following line to the end of the file:
which will open up gedit.  We want to add the following line to the end of the file:
<source lang='bash'>
<source lang='bash'>
0 4 1 * * cd /var/lib/iHRIS/sites/mySite/cron && bash archive_reports.sh
50 * * * * cd /var/lib/iHRIS/sites/mySite/cron && bash generate_reports_hourly.sh
10 2 * * * cd /var/lib/iHRIS/sites/mySite/cron && bash generate_reports_nightly.sh
 
</source>
</source>
save and quit.  This says that we will run the command on the first day of the month of every month at 4:00am.
save and quit.   
 
This says that we will run nightly report at 2:10 every morning.  The hourly report will get run at ten minutes before every hour.
 
Note, if you also set up [[Archive Reports Automatically |archiving of reports]] you will want to make sure that the nightly report generation has enough time to complete before starting the archiving.


==Adding a New Report==
==Adding a New Report==
Simply edit the file /var/lib/iHRIS/sites/mySite/cron.archive_reports.sh and add in the report view to the list of report views in the reports variable.
Simply edit the file /var/lib/iHRIS/sites/mySite/cron/generate_reports_hourly.sh and add in the report to the list of reports in the reports variable.
 
Don't forget to do "bzr commit cron/generate_reports_hourly.sh -m 'added open position report'"


Don't forget to do "bzr commit cron/archive_reports.sh -m 'added age distribution report'"
[[Category:Reports]][[Category:Review2013]]

Latest revision as of 12:11, 12 November 2013

This tutorial shows you how to generate reports automatically in the background with a cron job.

By default, iHRIS will launch automatically a background process to generate reports. However, this may be less than ideal on systems with higher load or a larger number of records. Instead, you may wish to schedule reports to be run at specific times. For example:

  • The search report should be run hourly -- this way new people added to the system will show up in the search page
  • Other reports should be run on a nightly basis

The first step is to determine the list of reports that you want to generate. You should also determine the frequency that you want them archive them on. In this example, based on iHRIS Botswana, we show you how to setup generation of hourly search reports and other reports nightly.

Turn Off Background Report Generation

See Configuring Report Generation Timing.

Getting the Report Name

You should first create a list of the reports that you want to generate For each of the report views that you want you can get the name/index of the report from the URL. The easiest way to do this is go to

  • Configure System
  • Reports

Now scroll over the "generate" link next to report that you are interested in with your mouse, and you should see a URL like:

 http://localhost/iHRIS/manage/CustomReports/generate/search_people

Then "search_people" is the name of the report.

Creating A Shell Script (Hourly)

In your site customizations, create a new top-level directory called "cron." For example if you site is at:

/var/lib/iHRIS/sites/mySite

you can do: <source lang='bash'> cd /var/lib/iHRIS/sites/mySite mkdir -p cron </source>

Now we want to create a shell script that will archive our reports from the command line. To so: <source lang='bash'>

cd /var/lib/iHRIS/sites/mySite/cron
gedit generate_reports_hourly.sh

</source> This will open up an editor. You want to add the following: <source lang='bash'>

  1. !/bin/bash

reports="search_people" for report in $reports do

   echo Archiving with /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/$report --nocheck=1
   /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/$report --nocheck=1

done </source> then save and exit. What this does is run through the list of reports (contained in the variable report) and generate them each individually

See iHRIS Botswana for an example.

Creating A Shell Script (Nightly)

In your site customizations, create a new top-level directory called "cron." For example if you site is at:

/var/lib/iHRIS/sites/mySite

you can do: <source lang='bash'> cd /var/lib/iHRIS/sites/mySite mkdir -p cron </source>

Now we want to create a shell script that will archive all reports from the command line. To do so: <source lang='bash'>

cd /var/lib/iHRIS/sites/mySite/cron
gedit generate_reports_nighly.sh

</source> This will open up an editor. You want to add the following: <source lang='bash'>

  1. !/bin/bash

do

   echo Archiving with /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force/ --nocheck=1
   /usr/bin/php ../pages//index.php --page=/CustomReports/generate_force --nocheck=1

done </source> then save and exit. This time, since we are generating all the reports, we did not need to list out each of the individual reports as the command will automatically try to generate them all.

Committing to bzr (Optional)

Of course we should commit our new shell script to bzr: <source lang='bash'> cd /var/lib/iHRIS/sites/mySite bzr add cron bzr commit -m "added shell script to handle generation of reports" </source>

Setting Up the Cron job

Now we need to tell our server to run the our new script, archive_reports.sh each month. To do so we do: <source lang='bash'> export VISUAL=gedit crontab -e </source> which will open up gedit. We want to add the following line to the end of the file: <source lang='bash'> 50 * * * * cd /var/lib/iHRIS/sites/mySite/cron && bash generate_reports_hourly.sh 10 2 * * * cd /var/lib/iHRIS/sites/mySite/cron && bash generate_reports_nightly.sh

</source> save and quit.

This says that we will run nightly report at 2:10 every morning. The hourly report will get run at ten minutes before every hour.

Note, if you also set up archiving of reports you will want to make sure that the nightly report generation has enough time to complete before starting the archiving.

Adding a New Report

Simply edit the file /var/lib/iHRIS/sites/mySite/cron/generate_reports_hourly.sh and add in the report to the list of reports in the reports variable.

Don't forget to do "bzr commit cron/generate_reports_hourly.sh -m 'added open position report'"