-
Notifications
You must be signed in to change notification settings - Fork 131
Example Process item
ggodart edited this page Jan 11, 2021
·
8 revisions
#-----------------------------------------------------------------------
# create the process item and a voice command to run it
# only needs to be run once so wrap in mnoloop
#-----------------------------------------------------------------------
#noloop=start
$v_backup_data = new Voice_Cmd('{run, } backup');
$p_backup_data = new Process_Item;
#noloop=stop
#-----------------------------------------------------------------------
# voice command handler to launch the backup
#-----------------------------------------------------------------------
if ( $state = said $v_backup) {
print_log("Backup launched");
# set up the process and start it
set $p_backup_data $config_parms{"code_dir"} . "/backup.sh";
$p_backup_data->set_output(
$config_parms{data_dir} . "/logs/backup.txt" );
$p_backup_data->set_timeout(600);
start $p_backup_data;
}
#-----------------------------------------------------------------------
# handler to launch run after the backup process ands
#-----------------------------------------------------------------------
if ( done_now $p_backup_data) {
if ( timed_out $p_backup_data) {
print_log('ERROR: backup.sh - timed out');
}
print_process_log( "backup.txt", "backup to ipage" );
}
#-----------------------------------------------------------------------
# utility subroutine called after any process ends to append its output
# to the print log, passed the name of the file to print
#-----------------------------------------------------------------------
sub print_process_log {
my ( $filename, $process_name ) = @_;
$filename = $config_parms{data_dir} . "/logs/" . $filename;
open( SOURCE, $filename );
while (<SOURCE>) {
chomp;
my $cline = $_;
print_log("[$process_name] $cline");
}
close(SOURCE);
truncate $filename, 0;
}