%evaluateClose
% Entry point for job close

%   Copyright 2014-2019 The MathWorks, Inc.

function out = evaluateClose()
out = [];

iCleanupPidFile();
parallel.internal.cluster.exitOnException(0);


% This function attempts to ensure we do not drool a java_pid file if it
% has been generated by this worker.
function iCleanupPidFile()

try
    javaTemp = char(java.lang.System.getProperty('java.io.tmpdir'));
    if isempty(javaTemp)
        return;
    end
    
    pid = feature('getpid');
    javaPidFile = fullfile(javaTemp, sprintf('.java_pid%i', pid));
    % We need to use fileattrib over exist because this is a socket file.
    if ~fileattrib(javaPidFile)
        return;
    end
    
    dctSchedulerMessage(6, 'Attempting to cleanup file: %s', javaPidFile);
    delete(javaPidFile);
catch e %#ok<NASGU>
    % Nothing we can do.
end
