2 use strict; use warnings;
4 # --------------------------------------------------------------------
5 # Loads the offline script files for a given org, sorts and runs the
6 # scripts, and returns the exception list
7 # --------------------------------------------------------------------
15 require 'offline-lib.pl';
17 my $org = $cgi->param('org');
18 my $resp = &process_data( &sort_data( &collect_data() ) );
20 handle_success("Scripts for org $org processed successfully <br/>" . JSON->perl2JSON($resp) );
24 # --------------------------------------------------------------------
25 # Collects all of the script logs into an in-memory structure that
27 # --------------------------------------------------------------------
30 handle_error("Org is not defined") unless $org;
31 my $dir = get_pending_dir($org);
32 handle_error("Batch from org $org is already in process") if (-e "$dir/lock");
34 # Lock the pending directory
35 system(("touch", "$dir/lock")) == 0 or handle_error("Unable to create lock file");
37 # Load the data from the files
41 while( ($file = <$dir/*.log>) ) {
42 $logger->debug("offline: Loading script file $file");
43 open(F, $file) or handle_error("Unable to open script file $file");
51 # --------------------------------------------------------------------
53 # --------------------------------------------------------------------
56 $logger->debug("offline: Sorting data");
61 # --------------------------------------------------------------------
62 # Runs the commands and returns the list of errors
63 # --------------------------------------------------------------------
68 $logger->activity("offline: Executing command $d");
73 # --------------------------------------------------------------------
74 # Moves the script files from the pending directory to the archive dir
75 # --------------------------------------------------------------------
77 my $archivedir = create_archive_dir($org);
78 my $pendingdir = get_pending_dir($org);
79 my $err = "Error moving offline logs from $pendingdir to $archivedir";
80 my @files = <$pendingdir/*.log>;
82 system( ("rm", "$pendingdir/lock") ) == 0 or handle_error($err);
83 system( ("mv", "@files", "$archivedir") ) == 0 or handle_error($err);
84 system( ("rmdir", "$pendingdir") ) == 0 or handle_error($err);
85 $logger->debug("offline: Archiving files to $archivedir");