Commit a6d1d462 authored by Brad Kennedy's avatar Brad Kennedy
Browse files

Added a wrapper script that allows the scheduler to tell that a job failed

Added License and removed exit for good ending jobs
parent 266449d1
% exit_wrapper() - function that wraps any script providing exit statuses
%
% Usage:
% >> octave exit_wrapper script-name
%
% Inputs:
% script-name - the script to watchdog
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
%
% Code written by Brad Kennedy
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
function ef_print_error(err)
builtin('disp', ['Error: ' err.message]);
output = '';
stack = err.stack;
for i = 1:numel(stack)
level = stack(i);
output = [output sprintf('\tat %s(%s:%d)\n', level.file, level.name, ...
level.line)];
end
builtin('disp', ['Stack trace:', char(10), output]);
end
......@@ -177,34 +177,31 @@ if ~isempty(batch_config.program_options);
end
end
%software...
if strcmp(batch_config.software,'none')
% TODO(brad) unsure what this is checking, find out why we have these
% magic numbers
while g.execstr(end)==10 || g.execstr(end)==13;
g.execstr=g.execstr(1:end-1);
end
% TODO(brad) this is a hack
qsubstr_tmp=sprintf('%s <(echo -e ''#!/bin/bash %s %s'')', qsubstr_tmp, '\n', g.execstr);
else
% Old nameing scheme that hardcoded the jobname - resulted in
% names that were too long.
[cPath,root_hfn,cExt]=fileparts(g.histfname);
[cPath,root_dfn,cExt]=fileparts(g.datafname);
c_mfn=[root_hfn,'_',root_dfn,'.m'];
% New Naming Scheme to use batch config jobname swapstring
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This variable piggy backs off of the string swap made in gen m
c_mfn = job_nameStr;
c_mfn = [c_mfn '.m'];
if length(c_mfn) >= 64
error('Script name too long! Please change your job name config.');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TODO(brad) this is a hack
qsubstr_tmp = sprintf('%s <(echo -e ''#!/bin/bash \n %s %s %s/%s'')', ...
qsubstr_tmp, ...
batch_config.software, program_options, g.execpath, c_mfn);
wrappername = 'analysis/support/dependencies/eeglab_asr_amica/plugins/batch_context/batch/exec_func/octave_exit_wrapper.m';
switch batch_config.software
case 'none'
% TODO(brad) unsure what this is checking, find out why we have these
% magic numbers
while g.execstr(end)==10 || g.execstr(end)==13;
g.execstr=g.execstr(1:end-1);
end
% TODO(brad) this is a hack
qsubstr_tmp=sprintf('%s <(echo -e ''#!/bin/bash %s %s'')', qsubstr_tmp, '\n', g.execstr);
otherwise
% New Naming Scheme to use batch config jobname swapstring
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This variable piggy backs off of the string swap made in gen m
c_mfn = job_nameStr;
c_mfn = [c_mfn '.m'];
if length(c_mfn) >= 64
error('Script name too long! Please change your job name config.');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TODO(brad) this is a hack
qsubstr_tmp = sprintf('%s <(echo -e ''#!/bin/bash \n %s %s %s %s/%s'')', ...
qsubstr_tmp, ...
batch_config.software, program_options, wrappername, g.execpath, c_mfn);
end
qsubstr = sprintf('%s%s;\n', g.qsubstr, qsubstr_tmp);
......
......@@ -172,29 +172,29 @@ if ~isempty(batch_config.program_options);
program_options=sprintf('%s %s',program_options,batch_config.program_options{i});
end
end
%software...
if strcmp(batch_config.software,'none')
while g.execstr(end)==10 || g.execstr(end)==13;
g.execstr=g.execstr(1:end-1);
end
qsubstr_tmp=sprintf('%s %s',qsubstr_tmp,g.execstr);
else
% Old nameing scheme that hardcoded the jobname - resulted in names that were to long.
[cPath,root_hfn,cExt]=fileparts(g.histfname);
[cPath,root_dfn,cExt]=fileparts(g.datafname);
c_mfn=[root_hfn,'_',root_dfn,'.m'];
% New Naming Scheme to use batch config jobname swapstring
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This variable piggy backs off of the string swap made in gen m
c_mfn = job_nameStr;
c_mfn = [c_mfn '.m'];
if length(c_mfn) >= 64
error('Script name too long! Please change your job name config.');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% software...
wrappername = 'analysis/support/dependencies/eeglab_asr_amica/plugins/batch_context/batch/exec_func/octave_exit_wrapper.m';
switch batch_config.software
case 'none'
while g.execstr(end)==10 || g.execstr(end)==13;
g.execstr=g.execstr(1:end-1);
end
qsubstr_tmp=sprintf('%s %s',qsubstr_tmp,g.execstr);
otherwise
% New Naming Scheme to use batch config jobname swapstring
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This variable piggy backs off of the string swap made in gen m
c_mfn = job_nameStr;
c_mfn = [c_mfn '.m'];
if length(c_mfn) >= 64
error('Script name too long! Please change your job name config.');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qsubstr_tmp=sprintf('%s %s %s %s/%s',qsubstr_tmp,batch_config.software,program_options,g.execpath,c_mfn);
qsubstr_tmp=sprintf('%s %s %s %s %s/%s', qsubstr_tmp, ...
batch_config.software, program_options, wrappername, ...
g.execpath, c_mfn);
end
qsubstr=sprintf('%s%s;\n',g.qsubstr,qsubstr_tmp);
......
% exit_wrapper() - function that wraps any script providing exit statuses
% to any failing Matlab/Octave script that doesn't receive
% a fatal signal.
% Note: We are not aware of how this functions with scripts
% with command line options themselves
%
% Usage:
% >> octave exit_wrapper script-name
%
% Inputs:
% script-name - the script to watchdog
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
%
% Code written by Brad Kennedy
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
arg_list = argv();
fname = arg_list{1};
arg_list = arg_list(2:end);
[pathstr, name, ext] = fileparts(fname);
fullpath = fullfile(pathstr, [name, ext]);
% Check if the directory/file exists
if exist(pathstr, 'dir') ~= 7
fprintf(['The specified file does not exist; The specified path' ...
'does not exist: %s'], pathstr);
exit(1);
end
if ~exist(fullpath, 'file')
fprintf('The specified file does not exist: %s\n', fullpath);
exit(1);
end
addpath([pwd, '/', pathstr]);
try
% We need a function handle
eval(['fhandle = @', name, ';']);
feval(fhandle, arg_list{:});
catch err
ef_print_error(err);
exit(1);
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment