-
Notifications
You must be signed in to change notification settings - Fork 209
/
JobResName.java
109 lines (94 loc) · 3.62 KB
/
JobResName.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qlangtech.tis.datax.job;
import com.qlangtech.tis.coredefine.module.action.TargetResName;
import com.qlangtech.tis.datax.TimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author: 百岁([email protected])
* @create: 2023-12-29 10:01
**/
public abstract class JobResName<T> extends TargetResName {
// private final EXEC jobExec;
private static final Logger logger = LoggerFactory.getLogger(JobResName.class);
public JobResName(String name //, EXEC jobExec
) {
super(name);
// this.jobExec = jobExec;
}
/**
* 创建默认
*
* @param jobName
* @param exec
* @param <T>
* @return
*/
public static <T> SubJobResName<T> createSubJob(String jobName, ThrowableConsumer<T> exec) {
final SubJobResName<T> created
= new SubJobResName<T>(jobName, new SubJobExec<T>() {
@Override
public void accept(T dto) throws JobOrchestrateException {
exec.accept(dto);
}
}) {
@Override
protected String getResourceType() {
return jobName;
}
};
return created;
}
public final void execSubJob(T t) throws JobOrchestrateException {
SSERunnable sse = SSERunnable.getLocal();
boolean success = false;
try {
sse.info(this.getName(), TimeFormat.getCurrentTimeStamp(), "〇〇 start to publish " + this.getResourceType() + "'" + this.getName() + "'");
this.execute(sse, t);
success = true;
sse.info(this.getName(), TimeFormat.getCurrentTimeStamp(), "✔✔ successful to publish " + this.getResourceType() + "'" + this.getName() + "'");
} catch (JobOrchestrateException e) {
logger.error(e.getMessage(), e);
throw e;
} finally {
if (!success) {
sse.info(this.getName(), TimeFormat.getCurrentTimeStamp(), "✕✕ faild to publish " + this.getResourceType() + "'" + this.getName() + "'");
}
sse.writeComplete(this, success);
}
}
protected abstract void execute(SSERunnable sse, T t) throws JobOrchestrateException;
// if (jobExec instanceof SubJobExec) {
// ((OwnerJobExec) jobExec).accept(t);
// } else {
// throw new UnsupportedOperationException("jobExec:" + jobExec.getClass());
// }
//}
protected abstract String getResourceType();
public interface OwnerJobExec<T, RESULT> {
public RESULT accept(T t) throws JobOrchestrateException;
}
public interface SubJobExec<T> {
public void accept(T t) throws JobOrchestrateException;
}
@FunctionalInterface
public interface ThrowableConsumer<T> {
void accept(T t) throws JobOrchestrateException;
}
}