-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker_4tests.m.template
76 lines (68 loc) · 2.19 KB
/
worker_4tests.m.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [ok,err_mess,je]=worker_4tests(worker_controls_string)
% function used as standard worker to do a job in a separate Matlab
% session.
%
% To work, should be present on a data search path, before Herbert is
% initialized as may need to initialize Herbert and Horace itself
%
%Inputs:
% worker_controls_string - the structure, containing information, necessary to
% initiate the job.
% Due to the fact this string is transferred
% through pipes its size is system dependent and limited, so
% contains only minimal initialization information, namely the
% folder name where the job initialization data are located on
% a remote system.
if nargin<1 || isempty(worker_controls_string)
worker_controls_string = getenv('WORKER_CONTROL_STRING');
end
je = [];
ok = false;
if isempty(which('herbert_init.m'))
try
herbert_on()
catch ME
err_mess = ME;
write_fail_log(ME)
return;
end
end
DO_LOGGING = getenv('DO_PARALLEL_MATLAB_LOGGING');
if isempty(DO_LOGGING)
DO_LOGGING = false;
else
DO_LOGGING = feval(DO_LOGGING);
end
DO_DEBUGGING = false;
try
[ok, err_mess,je] = parallel_worker(worker_controls_string,DO_LOGGING,DO_DEBUGGING);
catch ME1 % intercepted exception in processing failure or some odd bug indeed
write_fail_log(ME1);
err_mess = ME1;
end
if ~ok
write_fail_log(err_mess);
end
function write_fail_log(ERROR)
%
pid = int64(feature('getpid'));
log_file_name = sprintf('WORKER_V2_Process_%d_failure.log',pid);
log_file = fullfile(getuserdir,log_file_name );
if isa(ERROR,'MException')
error_contents = ERROR.getReport();
else
error_contents = evalc('disp(ERROR)');
end
fh = fopen(log_file,'w');
if fh<1
warning('Can not open log file %s for writing',log_file);
return; % well, can not write log file, sorry but logs can be available trough Matlab logs.
end
try
fprintf(fh,'******* Unhandled exception:\n');
fprintf(fh,'******** ERROR: \n');
fprintf(fh,'%s',error_contents );
stat = fclose(fh);
catch ERR % again, may be log will clarify the situation
warning('Can not write log file %s; Reason %s',log_file,getReport(ERR));
end