File: CheckQueue.m

package info (click to toggle)
openems 0.0.35+dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,288 kB
  • sloc: cpp: 40,259; yacc: 580; lex: 350; makefile: 258; sh: 169; ruby: 19
file content (60 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (2)
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
function [queue running] = CheckQueue(queue, query_time)
% function [queue running] = CheckQueue(queue, <query_time>)
%
% Check the given queue for finished tasks.
%
% Parameter:
%   query_time (optional): time interval to check for finished tasks
%                          (in seconds, default is 5)
%
% For more details see: InitQueue
%
% See also: InitQueue, ResultsQueue, Add2Queue, RunOpenEMS
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig

if ~isfield(queue,'jobs')
    running = 0;
    return
end

if (nargin<2)
    query_time = 5;
end

numJobs = numel(queue.jobs);

pause(query_time);

for n=1:numJobs
    if (queue.jobs_finished(n)==0)
        if (queue_checkProcess( queue.jobs{n}.pid, queue.jobs{n}.filenames)==0)
            queue.jobs_finished(n)=1;
            load(queue.jobs{n}.outargsfile);
            if ~isempty(err)
                disp(['Job with number ' num2str(n) ' failed to execute: Error message:']);
                error(['CheckQueue:' err.message]);
            end
            queue.jobs{n}.outargs = outargs;

            % read in output and cleanup
            [queue.jobs{n}.stdout,queue.jobs{n}.stderr] = queue_delProcess( queue.jobs{n}.pid, queue.jobs{n}.filenames );

            % cleanup
            delete( queue.jobs{n}.argsfile );
            clear queue.jobs{n}.argsfile;
            delete( queue.jobs{n}.outargsfile );
            clear queue.jobs{n}.outargsfile;

            queue.jobs_finished(n) = 1;

            if (queue.verbose>=1)
                disp(['CheckQueue: Job #' num2str(n) ' is finished!']);
            end
        end
    end
end

running = numel(queue.jobs_finished) - sum(queue.jobs_finished);