1、powerjob的安装部署
暂时省略
2、接入使用
1)注册应用
2)增加配置
在application.properties中增加对应配置
3)编写任务
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import tech.powerjob.worker.log.OmsLogger;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Optional;
@Slf4j
@Component("myProcessor")
public class MyProcessor implements BasicProcessor {
@Override
public ProcessResult process(TaskContext context) throws Exception {
// PowerJob 在线日志功能,使用该 Logger 打印的日志可以直接在 PowerJob 控制台查看
OmsLogger omsLogger = context.getOmsLogger();
omsLogger.info("StandaloneProcessorDemo start process,context is {}.", context);
//获取任务参数
String instanceParams = context.getJobParams();
JSONObject params = JSONObject.parseObject(instanceParams);
Integer day = params.getInteger("day");
return new ProcessResult(true, "process successfully~");
}
}
4)设置调度任务
参考文档:PowerJob 产品手册 · 语雀