mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: user-customized worker filter #215
This commit is contained in:
parent
770f30dd05
commit
83ac13b221
@ -47,7 +47,12 @@ public class SystemMetrics implements OmsSerializable, Comparable<SystemMetrics>
|
||||
* Used disk ratio.
|
||||
*/
|
||||
private double diskUsage;
|
||||
|
||||
/**
|
||||
* user-customized system metrics collector, eg. GPU usage
|
||||
* implement SystemMetricsCollector to set the value in worker side
|
||||
* implement WorkerFilter to filter the worker in server side
|
||||
*/
|
||||
private String extra;
|
||||
/**
|
||||
* Score of cache.
|
||||
*/
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.github.kfcfans.powerjob.server.extension;
|
||||
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.JobInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.remote.worker.cluster.WorkerInfo;
|
||||
|
||||
/**
|
||||
* filter worker by system metrics or other info
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2021/2/16
|
||||
*/
|
||||
public interface WorkerFilter {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param workerInfo worker info, maybe you need to use your customized info in SystemMetrics#extra
|
||||
* @param jobInfoDO job info
|
||||
* @return true will remove the worker in process list
|
||||
*/
|
||||
boolean filter(WorkerInfo workerInfo, JobInfoDO jobInfoDO);
|
||||
}
|
@ -3,7 +3,7 @@ logging.config=classpath:logback-dev.xml
|
||||
|
||||
####### Database properties(Configure according to the the environment) #######
|
||||
spring.datasource.core.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.core.jdbc-url=jdbc:mysql://localhost:3306/powerjob-daily?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
spring.datasource.core.jdbc-url=jdbc:mysql://localhost:3307/powerjob-daily?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
spring.datasource.core.username=root
|
||||
spring.datasource.core.password=No1Bug2Please3!
|
||||
spring.datasource.core.hikari.maximum-pool-size=20
|
||||
|
@ -33,7 +33,14 @@ public class WorkerHealthReporter implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
SystemMetrics systemMetrics = SystemInfoUtils.getSystemMetrics();
|
||||
SystemMetrics systemMetrics;
|
||||
|
||||
if (OhMyWorker.getConfig().getSystemMetricsCollector() == null) {
|
||||
systemMetrics = SystemInfoUtils.getSystemMetrics();
|
||||
} else {
|
||||
systemMetrics = OhMyWorker.getConfig().getSystemMetricsCollector().collect();
|
||||
}
|
||||
|
||||
WorkerHeartbeat heartbeat = new WorkerHeartbeat();
|
||||
|
||||
heartbeat.setSystemMetrics(systemMetrics);
|
||||
|
@ -3,6 +3,7 @@ package com.github.kfcfans.powerjob.worker.common;
|
||||
import com.github.kfcfans.powerjob.common.RemoteConstant;
|
||||
import com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy;
|
||||
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
|
||||
import com.github.kfcfans.powerjob.worker.extension.SystemMetricsCollector;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -53,4 +54,7 @@ public class OhMyConfig {
|
||||
* Test mode is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
|
||||
*/
|
||||
private boolean enableTestMode = false;
|
||||
|
||||
private SystemMetricsCollector systemMetricsCollector;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.github.kfcfans.powerjob.worker.extension;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.model.SystemMetrics;
|
||||
|
||||
/**
|
||||
* user-customized system metrics collector
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2021/2/16
|
||||
*/
|
||||
public interface SystemMetricsCollector {
|
||||
|
||||
/**
|
||||
* SystemMetrics, you can put your custom metrics info in the 'extra' param
|
||||
* @return SystemMetrics
|
||||
*/
|
||||
SystemMetrics collect();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user