function distcomp_evaluate_task_mvm(serializedTaskExecutionInfo)
% Evaluate the task stored in the serialized task execution info and submit
% its result to the job manager. This method is intended to be a thin
% wrapper around distcomp_evaluate_task to be used when MJS workers are
% launched with MVM.

% Copyright 2019-2021 The MathWorks, Inc.

% Deserialize the input arguments
taskExecutionInfo = com.mathworks.toolbox.distcomp.mjs.worker.matlab.MvmUtils.deserialize(serializedTaskExecutionInfo);

workerProxy = taskExecutionInfo.getWorker();
performJobInit = taskExecutionInfo.getPerformJobInit();
serializedCredentials = taskExecutionInfo.getSerializedCredentials();
performUserInit = taskExecutionInfo.getPerformUserInit();
postFcns = {};

% Perform the necessary initialization for this task and ensure that the
% necessary cleanup is done when the task finishes
if performUserInit
    username = char(serializedCredentials.getUserIdentity().getSimpleUsername());
    preMJSTask(username);
    postFcns = [{{@postMJSTask}}, postFcns];
end

% Prevent persistent variables from being cleared so we can know whether
% this MATLAB has just started
mlock;

% Perform worker initialization, if necessary
persistent justStarted
justStarted = isempty(justStarted);
if justStarted
    pid = []; % Use the parent process pid
    startRequestServer = false; % MVM workers don't need the pctRequestServer
    initworker(pid, startRequestServer);
end

distcomp_evaluate_task(workerProxy, performJobInit, justStarted, serializedCredentials, taskExecutionInfo, postFcns)
