EllisLab text mark
Advanced Search
Batch library
Posted: 23 May 2012 06:21 AM
Joined: 2012-05-23
3 posts

I have a problem - to perform many intensive function after submitting the form. Such example:

1. The user loads the XML with tags - name, url, mail, date (dd-mm-YY) etc.. Above 1000-5000 records.
2. I need to valid name, download file form url, save to folder, valid mail, convert date to Unixtime and save results to database (with merge if exist).

There are many similar tasks in the project, so I decided to write a universal ajax-batch library for using it in future.

How it works:

1. submit the form.
2. creating array of functions to be performed as example:

$process = array(
'function_name', array($arg1$arg2)),
'function_name', array($arg1$arg2))

3. redirect to batch-controller page with post of this array
4. page sends arguments to batch-execute-page via AJAX (batch_id, current_id, arg1, arg2 ....), returning JSON data (success or not, some result params etc..)
5. using progress bar with some messages on this page
6. redirect user to success/error page.

All code for creating batch as this:

$data $some_array();
$process = array();
foreach (
$data as $params{
= array('my_example_function', array($params[0]$params[1]));
= array(
'id' => 'xml_batch'.time(),
'process' => $process,
'access' => array('function', array($access_arg))  //Function which return access user for this batch
'redirect' => 'users/john/parsexml' //page to redirect after finish the batch
'messages' => array('success' => 'Wow!','error'=>'Sorry!'),
'maxtime' time() + 3600

This code create temporary file in some directory (xml_batch_8129133194_85345345345.tmp) with params, which will use the controller on batch-execute-page. when the time comes (maxtime params) - file will removed. Before that time, the process will fail - it will stop. Obsolete files are automatically deleted after launch cron.A similar mechanism is used in the CMS Drupal.

For using also needed to include JS ajax-queue-library.

My question to the developers:
A. Is there a ready library for such tasks for CodeIgniter?
B. If not, in the right direction I’m developing?

P.S. Sorry for my bad English ((

Posted: 24 May 2012 02:11 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-05-23
3 posts

Does not anyone faced with this task? confused