pangyang 2 months ago
commit 8aeb54c20d
  1. 24
      blade-ops/blade-job/src/main/java/org/springblade/job/processor/scheduling/SchedulingProcessor.java
  2. 39
      blade-service-api/blade-scheduling-api/src/main/java/org/springblade/scheduling/config/NoRetryFeignConfig.java
  3. 4
      blade-service-api/blade-scheduling-api/src/main/java/org/springblade/scheduling/feign/IWorkOrderClient.java
  4. 1
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/SchedulingApplication.java
  5. 2
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/task/InitResourceJob.java
  6. 2
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/task/SchedulingJob.java

@ -10,7 +10,6 @@ import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/**
* 排产-排产定时任务
@ -25,28 +24,9 @@ public class SchedulingProcessor implements BasicProcessor {
@Override
public ProcessResult process(TaskContext context) throws Exception {
log.info("排产定时任务开始,任务ID:{}", context.getTaskId()); // 增加任务ID便于排查
try {
// 同步执行(或等待异步执行完成),避免任务提前返回
CompletableFuture<Void> runFuture = CompletableFuture.runAsync(() -> {
try {
log.info("开始执行排产逻辑");
client.scheduling();
log.info("排产逻辑执行完成");
} catch (Exception e) {
log.error("client.scheduling()执行异常", e);
throw new RuntimeException(e); // 抛出异常让外层感知
}
});
// 等待异步任务完成(避免任务提前结束),可设置超时时间
runFuture.get(60, TimeUnit.MINUTES); // 假设排产最多执行60分钟,根据实际调整
log.info("排产定时任务开始");
CompletableFuture<Void> runFuture = CompletableFuture.runAsync(()->client.scheduling());
log.info("排产定时任务结束");
return new ProcessResult(true);
} catch (Exception e) {
log.error("排产定时任务执行失败", e);
return new ProcessResult(false); // 明确返回失败,避免框架重试
}
}
}

@ -0,0 +1,39 @@
package org.springblade.scheduling.config;
import feign.Request;
import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* TODO功能描述
*
* @author sjx
* @version 1.0
* @BelongsProject jonhon-mes-svr
* @BelongsPackage org.springblade.scheduling.config
* @since 2026-02-10 15:07
*/
@Configuration
@ComponentScan
public class NoRetryFeignConfig {
/**
* 配置永不重试的RetryerFeign内置的NEVER_RETRY常量
*/
@Bean
public Retryer feignRetryer() {
// Retryer.NEVER_RETRY 表示:初始间隔0,最大间隔0,最大重试次数0 → 完全不重试
return Retryer.NEVER_RETRY;
}
/**
* 2. 显式配置超时时间关键覆盖默认60秒与yml保持12秒一致
*/
@Bean
public Request.Options feignRequestOptions() {
int connectTimeout = 5 * 60 * 1000; // 300000ms
int readTimeout = 24 * 60 * 60 * 1000; // 86400000ms
return new Request.Options(connectTimeout, readTimeout);
}
}

@ -2,6 +2,7 @@ package org.springblade.scheduling.feign;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.tool.api.R;
import org.springblade.scheduling.config.NoRetryFeignConfig;
import org.springblade.scheduling.pojo.vo.GlassCakeOrderPageQuery;
import org.springblade.scheduling.pojo.vo.WorkOrderVO;
import org.springframework.cloud.openfeign.FeignClient;
@ -17,7 +18,8 @@ import org.springframework.web.bind.annotation.GetMapping;
* @since 2026-01-16 10:06
*/
@FeignClient(
value = "blade-scheduling"
value = "blade-scheduling",
configuration = NoRetryFeignConfig.class
)
public interface IWorkOrderClient {
String API_PREFIX = "/feign/client/workOrder";

@ -36,6 +36,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @author Chill
*/
@BladeCloudApplication
@EnableScheduling
public class SchedulingApplication {
public static void main(String[] args) {

@ -22,7 +22,7 @@ public class InitResourceJob {
private final IPersonResourceService personResourceService;
private final IEquipResourceService equipResourceService;
//@Scheduled(cron = "* * 1 * * ?")
@Scheduled(cron = "* * 1 * * ?")
public void initResourceJob() {
equipResourceService.initEquipResource();
personResourceService.initPersonResource();

@ -21,7 +21,7 @@ import org.springframework.stereotype.Component;
public class SchedulingJob {
private final IWorkOrderService workOrderService;
//@Scheduled(cron = "0 0 8,12,16,20 * * ? ")
@Scheduled(cron = "0 0 8,12,16,20 * * ? ")
public void schedulingJob() {
workOrderService.scheduling();
}

Loading…
Cancel
Save