Created
March 10, 2023 05:57
-
-
Save tzengshinfu/ef6747fb905a465f0395f074bfd36d20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.*******.apiserver.webapi.config; | |
import java.util.Arrays; | |
import javax.validation.constraints.NotBlank; | |
import javax.validation.constraints.NotNull; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import lombok.Data; | |
import tech.powerjob.common.enums.Protocol; | |
import tech.powerjob.worker.PowerJobSpringWorker; | |
import tech.powerjob.worker.common.PowerJobWorkerConfig; | |
import tech.powerjob.worker.common.constants.StoreStrategy; | |
@Configuration | |
@Data | |
public class PowerJobConfig { | |
@NotBlank | |
@Value("${powerjob.worker.app-name}") | |
private String appName; | |
@NotBlank | |
@Value("${powerjob.worker.server-address}") | |
private String serverAddress; | |
@NotNull | |
@Value("${powerjob.worker.port}") | |
private int port; | |
@NotBlank | |
@Value("${powerjob.worker.protocol}") | |
private String protocol; | |
@NotNull | |
@Value("${powerjob.worker.enableTestMode}") | |
private boolean enableTestMode; | |
@NotBlank | |
@Value("${powerjob.worker.store-strategy}") | |
private String storeStrategy; | |
@NotNull | |
@Value("${powerjob.worker.max-result-length}") | |
private int maxResultLength; | |
@NotNull | |
@Value("${powerjob.worker.max-appended-wf-context-length}") | |
private int maxAppendedWFContextLength; | |
@NotNull | |
@Value("${powerjob.worker.max-lightweight-task-num}") | |
private int maxLightweightTaskNum; | |
@NotNull | |
@Value("${powerjob.worker.max-heavy-task-num}") | |
private int maxHeavyTaskNum; | |
@NotNull | |
@Value("${powerjob.worker.healthReportInterval}") | |
private int healthReportInterval; | |
@NotBlank | |
@Value("${powerjob.worker.callee-address}") | |
private String calleeAddress; | |
@NotBlank | |
@Value("${powerjob.worker.callee-protocol}") | |
private String calleeProtocol; | |
@NotNull | |
@Value("${powerjob.worker.callee-timeout}") | |
private int calleeTimeout; | |
@Bean | |
PowerJobSpringWorker initPowerJobSpringWorker() { | |
var config = new PowerJobWorkerConfig(); | |
config.setAppName(appName); | |
config.setServerAddress(Arrays.asList(serverAddress.split(","))); | |
config.setPort(port); | |
config.setProtocol(Protocol.of(protocol)); | |
config.setEnableTestMode(enableTestMode); | |
config.setStoreStrategy(StoreStrategy.valueOf(storeStrategy)); | |
config.setMaxResultLength(maxResultLength); | |
config.setMaxAppendedWfContextLength(maxAppendedWFContextLength); | |
config.setMaxLightweightTaskNum(maxLightweightTaskNum); | |
config.setMaxHeavyweightTaskNum(maxHeavyTaskNum); | |
config.setHealthReportInterval(healthReportInterval); | |
return new PowerJobSpringWorker(config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment