package cd.casic.ci.process.engine.worker;


import cd.casic.ci.process.common.WorkAtom;
import cd.casic.ci.process.engine.runContext.TaskRunContext;
import cd.casic.ci.process.engine.worker.base.BaseWorker;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.framework.commons.exception.ServiceException;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;


@Slf4j
@WorkAtom(taskType = "ERROR_SUCCESS")
public class TestErrorWorker extends BaseWorker {
    @Override
    public void execute(TaskRunContext context) {
        if (context.getContextDef() instanceof PipTask task) {
            Map<String, Object> taskProperties = task.getTaskProperties();
            String s = String.valueOf(taskProperties.get("buildScript"));
            if ("error".equals(s)) {
                append(context,"执行报错");
                throw new ServiceException(111,"模拟测试报错");
            }
            append(context,"执行成功");
        }
    }
}
