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
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 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.
There is also  


==Getting the Report Views==
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 onIn this example, based on iHRIS Botswana, we show you how to setup generation of hourly search reports and other reports nightly.
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:
  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:
==Turn Off Background Report Generation==
facility_list 11238232 search_people
See [[Configuring Report Generation Timing]].   
 
Note: this saves the default "export" of the report, which is usually an spreadsheetSo if you select a report view which is a graph, you will archive the underlying data rather than the graph itself.


==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==
==Creating A Shell Script==
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:

Revision as of 09:57, 8 December 2011

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

There is also

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

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 archive_reports.sh

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

  1. !/bin/bash

reports="facility_list 11238232 search_people" for report in $reports do

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

done </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


See iHRIS Botswana for an example.

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 archiving 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'> 0 4 1 * * cd /var/lib/iHRIS/sites/mySite/cron && bash archive_reports.sh </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.

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.

Don't forget to do "bzr commit cron/archive_reports.sh -m 'added age distribution report'"