add schedule config

This commit is contained in:
JiyangTang 2024-01-10 10:08:35 +08:00
parent 2f3631cc91
commit acff6b1cd8
3 changed files with 24 additions and 25 deletions

View File

@ -53,6 +53,7 @@ public class AppleInventorySchedule {
@Resource
private IphoneProductParserUtils iphoneProductParserUtils;
@Resource
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
@ -68,7 +69,7 @@ public class AppleInventorySchedule {
products.forEach(product -> {
this.doMonitor(product);
try {
Thread.sleep(1500);
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(">>>>>>>>>>apple inventory monitor error:{}<<<<<<<<<<", e.getMessage(), e);
}
@ -96,7 +97,6 @@ public class AppleInventorySchedule {
return;
}
JSONObject responseJsonObject = JSON.parseObject(httpResponse.body());
// log.info(">>>>>>>>>>query apple inventory response:{}<<<<<<<<<<", responseJsonObject);
JSONObject pickupMessage = responseJsonObject.getJSONObject("body").getJSONObject("content").getJSONObject("pickupMessage");
JSONArray stores = pickupMessage.getJSONArray("stores");
if (stores == null) {
@ -110,12 +110,9 @@ public class AppleInventorySchedule {
StringBuilder pushContentBuilder = new StringBuilder();
List<String> availableStoreNameList = stores.stream()
.filter(store -> filterStore((JSONObject) store))
.filter(k ->
judgingStoreInventory((JSONObject) k, product.getModel()))
.map(store -> {
JSONObject storeJson = (JSONObject) store;
return storeJson.getString("storeName").trim();
})
.filter(k -> judgingStoreInventory((JSONObject) k, product.getModel()))
.map(store -> ((JSONObject) store).getString("storeName")
.trim())
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(availableStoreNameList)) {
return;
@ -161,7 +158,8 @@ public class AppleInventorySchedule {
return Boolean.TRUE;
}
String storeName = storeInfo.getString("storeName");
return storeList.stream().anyMatch(k -> storeName.contains(k) || k.contains(storeName));
return storeList.stream()
.anyMatch(k -> storeName.contains(k) || k.contains(storeName));
}
/**

View File

@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import java.util.concurrent.ThreadPoolExecutor;
@ -46,18 +48,15 @@ public class ExecutorConfig {
return executor;
}
@Bean("scheduleExecutor")
public ThreadPoolTaskExecutor scheduleExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix(appName + "-schedule-");
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setKeepAliveSeconds(keepAliveSecond);
executor.setQueueCapacity(queueCapacity);
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.initialize();
return executor;
@Bean("taskExecutor")
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(maxPoolSize);
taskScheduler.setThreadNamePrefix(appName + "-schedule-");
taskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
taskScheduler.setPoolSize(10);
return taskScheduler;
}
}

View File

@ -1,8 +1,8 @@
package top.baogutang.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import javax.annotation.Resource;
@ -15,11 +15,13 @@ import javax.annotation.Resource;
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
@Resource(name = "scheduleExecutor")
private ThreadPoolTaskExecutor scheduleExecutor;
@Resource(name = "taskExecutor")
private TaskScheduler taskScheduler;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.setScheduler(scheduleExecutor);
scheduledTaskRegistrar.setScheduler(taskScheduler);
}
}