add schedule config
This commit is contained in:
parent
2f3631cc91
commit
acff6b1cd8
@ -53,6 +53,7 @@ public class AppleInventorySchedule {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IphoneProductParserUtils iphoneProductParserUtils;
|
private IphoneProductParserUtils iphoneProductParserUtils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
|
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ public class AppleInventorySchedule {
|
|||||||
products.forEach(product -> {
|
products.forEach(product -> {
|
||||||
this.doMonitor(product);
|
this.doMonitor(product);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1500);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.error(">>>>>>>>>>apple inventory monitor error:{}<<<<<<<<<<", e.getMessage(), e);
|
log.error(">>>>>>>>>>apple inventory monitor error:{}<<<<<<<<<<", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@ -96,7 +97,6 @@ public class AppleInventorySchedule {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject responseJsonObject = JSON.parseObject(httpResponse.body());
|
JSONObject responseJsonObject = JSON.parseObject(httpResponse.body());
|
||||||
// log.info(">>>>>>>>>>query apple inventory response:{}<<<<<<<<<<", responseJsonObject);
|
|
||||||
JSONObject pickupMessage = responseJsonObject.getJSONObject("body").getJSONObject("content").getJSONObject("pickupMessage");
|
JSONObject pickupMessage = responseJsonObject.getJSONObject("body").getJSONObject("content").getJSONObject("pickupMessage");
|
||||||
JSONArray stores = pickupMessage.getJSONArray("stores");
|
JSONArray stores = pickupMessage.getJSONArray("stores");
|
||||||
if (stores == null) {
|
if (stores == null) {
|
||||||
@ -110,12 +110,9 @@ public class AppleInventorySchedule {
|
|||||||
StringBuilder pushContentBuilder = new StringBuilder();
|
StringBuilder pushContentBuilder = new StringBuilder();
|
||||||
List<String> availableStoreNameList = stores.stream()
|
List<String> availableStoreNameList = stores.stream()
|
||||||
.filter(store -> filterStore((JSONObject) store))
|
.filter(store -> filterStore((JSONObject) store))
|
||||||
.filter(k ->
|
.filter(k -> judgingStoreInventory((JSONObject) k, product.getModel()))
|
||||||
judgingStoreInventory((JSONObject) k, product.getModel()))
|
.map(store -> ((JSONObject) store).getString("storeName")
|
||||||
.map(store -> {
|
.trim())
|
||||||
JSONObject storeJson = (JSONObject) store;
|
|
||||||
return storeJson.getString("storeName").trim();
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollectionUtils.isEmpty(availableStoreNameList)) {
|
if (CollectionUtils.isEmpty(availableStoreNameList)) {
|
||||||
return;
|
return;
|
||||||
@ -161,7 +158,8 @@ public class AppleInventorySchedule {
|
|||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
String storeName = storeInfo.getString("storeName");
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
@ -46,18 +48,15 @@ public class ExecutorConfig {
|
|||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("scheduleExecutor")
|
@Bean("taskExecutor")
|
||||||
public ThreadPoolTaskExecutor scheduleExecutor() {
|
public TaskScheduler taskScheduler() {
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||||
executor.setThreadNamePrefix(appName + "-schedule-");
|
taskScheduler.setPoolSize(maxPoolSize);
|
||||||
executor.setCorePoolSize(corePoolSize);
|
taskScheduler.setThreadNamePrefix(appName + "-schedule-");
|
||||||
executor.setMaxPoolSize(maxPoolSize);
|
taskScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
executor.setKeepAliveSeconds(keepAliveSecond);
|
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
executor.setQueueCapacity(queueCapacity);
|
taskScheduler.setPoolSize(10);
|
||||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
return taskScheduler;
|
||||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
|
||||||
executor.initialize();
|
|
||||||
return executor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package top.baogutang.common.config;
|
package top.baogutang.common.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
||||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -15,11 +15,13 @@ import javax.annotation.Resource;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class ScheduleConfig implements SchedulingConfigurer {
|
public class ScheduleConfig implements SchedulingConfigurer {
|
||||||
|
|
||||||
@Resource(name = "scheduleExecutor")
|
@Resource(name = "taskExecutor")
|
||||||
private ThreadPoolTaskExecutor scheduleExecutor;
|
private TaskScheduler taskScheduler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
||||||
scheduledTaskRegistrar.setScheduler(scheduleExecutor);
|
|
||||||
|
scheduledTaskRegistrar.setScheduler(taskScheduler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user