package com.gyee.generation.processors;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import tech.powerjob.official.processors.CommonBasicProcessor;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.WorkflowContext;
import tech.powerjob.worker.log.OmsLogger;

import java.util.Date;
import java.util.Map;

/**
 * @description: 工作流调度任务测试
 * @author: shilin
 * @date: 2024/5/29 9:19
 * @param:
 * @return:
 **/
@Slf4j
@Component("testBaseProcessor3")
public class StandaloneProcessor3Demo extends CommonBasicProcessor {

    @Override
    protected ProcessResult process0(TaskContext taskContext) {

        String jobParams = taskContext.getJobParams();
        OmsLogger omsLogger = taskContext.getOmsLogger();
        try {

            WorkflowContext workflowContext = taskContext.getWorkflowContext();

            workflowContext.appendData2WfContext("test3", new Date());

            Map<String, String> map=  workflowContext.fetchWorkflowContext();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
            }
        } catch (Exception e) {
            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
            return new ProcessResult(false);
        }
        return new ProcessResult(true);
    }
}
