function invalidateTask(task)
% invalidateTask - Safely invalidate a task object. Used when the
% associated parent job is deleted.

%   Copyright 2020 The MathWorks, Inc.

    try
        delete(task, 'invalidateOnly');
    catch E
        % We are trying to natively delete the underlying
        % tasks associated with this job, but we are
        % sporadically seeing that the class of tasks is
        % NOT a subclass of CustomGetSet. For debugging
        % purposes we are going to warn (which will still
        % cause test failures but hopefully this will give
        % us more info on what is going on
        warning( 'parallel:job:UnexpectedInternalError', 'The class of task is : %s\n\nThe underlying error message is : \n%s', class(task), E.getReport );
    end
end

