Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jobs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
jobs
Commits
d1487b51
Commit
d1487b51
authored
Oct 31, 2018
by
zhangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
d17d6fe2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
12 deletions
+28
-12
pom.xml
pom.xml
+2
-2
JobCommon.java
src/main/java/com/egolm/jobs/config/schedule/JobCommon.java
+3
-2
ScheduleJob.java
...main/java/com/egolm/jobs/config/schedule/ScheduleJob.java
+7
-5
ScheduleUtils.java
...in/java/com/egolm/jobs/config/schedule/ScheduleUtils.java
+2
-1
JobController.java
src/main/java/com/egolm/jobs/controller/JobController.java
+2
-1
application-dev.properties
src/main/resources/application-dev.properties
+12
-1
No files found.
pom.xml
View file @
d1487b51
...
@@ -21,11 +21,11 @@
...
@@ -21,11 +21,11 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
<dependency>
<!-- <dependency> https://blog.csdn.net/liuxiaochang_2011/article/details/80663093
<groupId>org.springframework.boot</groupId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<optional>true</optional>
</dependency>
</dependency>
-->
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
...
...
src/main/java/com/egolm/jobs/config/schedule/JobCommon.java
View file @
d1487b51
package
com
.
egolm
.
jobs
.
config
.
schedule
;
package
com
.
egolm
.
jobs
.
config
.
schedule
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.Date
;
public
class
JobCommon
{
public
class
JobCommon
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
sJobID
;
private
String
sJobID
;
private
Integer
nRunFlg
;
private
Integer
nRunFlg
;
private
String
sCronExpression
;
private
String
sCronExpression
;
...
...
src/main/java/com/egolm/jobs/config/schedule/ScheduleJob.java
View file @
d1487b51
...
@@ -4,23 +4,23 @@ import org.quartz.JobExecutionContext;
...
@@ -4,23 +4,23 @@ import org.quartz.JobExecutionContext;
import
org.quartz.JobExecutionException
;
import
org.quartz.JobExecutionException
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.jobs.JobsApplication
;
import
com.egolm.jobs.service.JobService
;
import
com.egolm.jobs.service.JobService
;
public
class
ScheduleJob
extends
QuartzJobBean
{
public
class
ScheduleJob
extends
QuartzJobBean
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ScheduleJob
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ScheduleJob
.
class
);
@Autowired
private
JobService
jobService
;
/**
/**
* 计划任务执行入口
* 计划任务执行入口
*/
*/
@Override
@Override
protected
void
executeInternal
(
JobExecutionContext
context
)
throws
JobExecutionException
{
protected
void
executeInternal
(
JobExecutionContext
context
)
throws
JobExecutionException
{
System
.
out
.
println
(
context
.
getMergedJobDataMap
().
get
(
ScheduleConfig
.
JOB_PARAM_KEY
));
JobCommon
jobCommon
=
(
JobCommon
)
context
.
getMergedJobDataMap
().
get
(
ScheduleConfig
.
JOB_PARAM_KEY
);
JobCommon
jobCommon
=
(
JobCommon
)
context
.
getMergedJobDataMap
().
get
(
ScheduleConfig
.
JOB_PARAM_KEY
);
String
sJobID
=
jobCommon
.
getsJobID
();
String
sJobID
=
jobCommon
.
getsJobID
();
Object
data
=
jobCommon
.
getData
();
Object
data
=
jobCommon
.
getData
();
...
@@ -30,6 +30,8 @@ public class ScheduleJob extends QuartzJobBean {
...
@@ -30,6 +30,8 @@ public class ScheduleJob extends QuartzJobBean {
}
}
//调用业务逻辑
//调用业务逻辑
JobService
jobService
=
JobsApplication
.
getBean
(
JobService
.
class
);
System
.
out
.
println
(
jobService
);
jobService
.
executeJob
(
jobCommon
);
jobService
.
executeJob
(
jobCommon
);
}
}
...
...
src/main/java/com/egolm/jobs/config/schedule/ScheduleUtils.java
View file @
d1487b51
...
@@ -88,6 +88,7 @@ public class ScheduleUtils {
...
@@ -88,6 +88,7 @@ public class ScheduleUtils {
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
ScheduleJob
.
class
).
withIdentity
(
jobKey
).
build
();
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
ScheduleJob
.
class
).
withIdentity
(
jobKey
).
build
();
jobDetail
.
getJobDataMap
().
put
(
ScheduleConfig
.
JOB_PARAM_KEY
,
jobCommon
);
jobDetail
.
getJobDataMap
().
put
(
ScheduleConfig
.
JOB_PARAM_KEY
,
jobCommon
);
scheduler
.
scheduleJob
(
jobDetail
,
trigger
);
scheduler
.
scheduleJob
(
jobDetail
,
trigger
);
// 暂停任务
if
(
nRunFlg
==
RunFlag
.
PAUSE
.
getValue
())
{
if
(
nRunFlg
==
RunFlag
.
PAUSE
.
getValue
())
{
pauseJob
(
scheduler
,
sJobID
);
pauseJob
(
scheduler
,
sJobID
);
}
}
...
...
src/main/java/com/egolm/jobs/controller/JobController.java
View file @
d1487b51
...
@@ -44,13 +44,14 @@ public class JobController {
...
@@ -44,13 +44,14 @@ public class JobController {
Map
<
String
,
Object
>
params
=
jobService
.
queryById
(
id
);
Map
<
String
,
Object
>
params
=
jobService
.
queryById
(
id
);
if
(
params
!=
null
)
{
if
(
params
!=
null
)
{
if
(
type
.
equals
(
"start"
))
{
if
(
type
.
equals
(
"start"
))
{
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
id
);
JobCommon
jobCommon
=
new
JobCommon
();
JobCommon
jobCommon
=
new
JobCommon
();
jobCommon
.
setsJobID
(
id
);
jobCommon
.
setsJobID
(
id
);
jobCommon
.
setnRunFlg
(
0
);
jobCommon
.
setnRunFlg
(
0
);
jobCommon
.
setsCronExpression
(
params
.
get
(
"sCron"
)+
""
);
jobCommon
.
setsCronExpression
(
params
.
get
(
"sCron"
)+
""
);
jobCommon
.
setData
(
params
.
get
(
"sClass"
));
jobCommon
.
setData
(
params
.
get
(
"sClass"
));
ScheduleUtils
.
createScheduleJob
(
scheduler
,
jobCommon
);
ScheduleUtils
.
createScheduleJob
(
scheduler
,
jobCommon
);
ScheduleUtils
.
r
esumeJob
(
scheduler
,
id
);
ScheduleUtils
.
r
un
(
scheduler
,
jobCommon
);
}
else
if
(
type
.
equals
(
"stop"
))
{
}
else
if
(
type
.
equals
(
"stop"
))
{
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
id
);
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
id
);
}
else
{
}
else
{
...
...
src/main/resources/application-dev.properties
View file @
d1487b51
...
@@ -20,3 +20,14 @@ spring.datasource.shop.testWhileIdle=true
...
@@ -20,3 +20,14 @@ spring.datasource.shop.testWhileIdle=true
spring.datasource.shop.validationQueryTimeout
=
5
spring.datasource.shop.validationQueryTimeout
=
5
spring.datasource.shop.validationQuery
=
SELECT 1
spring.datasource.shop.validationQuery
=
SELECT 1
spring.datasource.shop.timeBetweenEvictionRunsMillis
=
3600000
spring.datasource.shop.timeBetweenEvictionRunsMillis
=
3600000
spring.redis.database
=
0
spring.redis.host
=
10.10.0.15
spring.redis.port
=
16379
spring.redis.password
=
spring.redis.timeout=2000
spring.redis.pool.max-active
=
20
spring.redis.pool.max-wait
=
2000
spring.redis.pool.max-idle
=
5
spring.redis.pool.min-idle
=
0
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment