Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
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
李丛阳
education
Commits
e3270179
Commit
e3270179
authored
Jan 19, 2018
by
李丛阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QuartzConfig
parent
d386e232
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
103 additions
and
32 deletions
+103
-32
BCodeLxcServiceImpl.java
...soft/business/bcode/service/impl/BCodeLxcServiceImpl.java
+2
-10
ClearLxcJob.java
...ain/java/org/rcisoft/business/bcode/task/ClearLxcJob.java
+8
-7
RcApplicationRunner.java
...a/org/rcisoft/business/component/RcApplicationRunner.java
+50
-0
ApplicationContextHolder.java
...rg/rcisoft/common/component/ApplicationContextHolder.java
+2
-2
MvcConfig.java
src/main/java/org/rcisoft/config/MvcConfig.java
+1
-12
TaskUtil.java
src/main/java/org/rcisoft/core/util/TaskUtil.java
+39
-0
application.yml
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/org/rcisoft/business/bcode/service/impl/BCodeLxcServiceImpl.java
View file @
e3270179
...
...
@@ -12,6 +12,7 @@ import org.rcisoft.core.result.ResultCode;
import
org.rcisoft.core.service.RcRedisService
;
import
org.rcisoft.core.service.SerializationUtils
;
import
org.rcisoft.core.util.FreemarkerUtil
;
import
org.rcisoft.core.util.TaskUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.quartz.SchedulerFactoryBean
;
import
org.springframework.stereotype.Service
;
...
...
@@ -117,17 +118,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
.
withIdentity
(
global
.
getLxcPrefix
()
+
lxc
.
getUserId
())
.
startAt
(
endTime
).
build
();
// 触发器时间设定
Scheduler
sched
=
schedulerFactoryBean
.
getScheduler
();
/*触发器*/
try
{
sched
.
scheduleJob
(
job
,
trigger
);
// 启动
if
(!
sched
.
isShutdown
())
{
sched
.
start
();
}
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
());
}
TaskUtil
.
startSchedule
(
schedulerFactoryBean
.
getScheduler
(),
trigger
,
job
);
/*5.端口放进去 */
rcRedisServiceImpl
.
setList
(
"lxcKeys"
,
key
);
...
...
src/main/java/org/rcisoft/business/bcode/task/ClearLxcJob.java
View file @
e3270179
...
...
@@ -70,14 +70,16 @@ public class ClearLxcJob implements Job {
if
(
null
!=
shutdown
&&
shutdown
.
after
(
new
Date
()))
return
;
/*到点了*/
containerPath
=
global
.
get
BASE
_UPLOAD_SERVER_LOCATION
()
+
File
.
separator
+
containerPath
=
global
.
get
PHYSICAL
_UPLOAD_SERVER_LOCATION
()
+
File
.
separator
+
global
.
getLxcDockerfilePath
()
+
File
.
separator
+
lxc
.
getUserId
()
+
File
.
separator
;
/*关闭容器*/
/*2.docker-compose 起容器*/
CommandResult
commandResult
=
null
;
commandResult
=
lxcCommand
.
startOrDownLxc
(
containerPath
,
false
);
/*关闭失败 返回 不删除key*/
if
(!
commandResult
.
isSuccess
())
return
;
}
/*3.移除容器*/
rcRedisServiceImpl
.
remove
(
key
);
/*4.移除端口*/
...
...
@@ -85,5 +87,4 @@ public class ClearLxcJob implements Job {
key
);
rcRedisServiceImpl
.
removeList
(
"lxcPorts"
,
lxc
.
getContainerPort
()
+
""
);
}
}
}
src/main/java/org/rcisoft/business/
listener/RcListe
ner.java
→
src/main/java/org/rcisoft/business/
component/RcApplicationRun
ner.java
View file @
e3270179
package
org
.
rcisoft
.
business
.
listener
;
package
org
.
rcisoft
.
business
.
component
;
import
lombok.extern.slf4j.Slf4j
;
import
org.quartz.*
;
import
org.rcisoft.business.bcode.task.ClearLxcJob
;
import
org.rcisoft.core.util.TaskUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.scheduling.quartz.SchedulerFactoryBean
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
import
java.util.HashMap
;
/**
* Created by lcy on 18/1/
19
.
* Created by lcy on 18/1/
20
.
*
*
*
* JobDetail job = JobBuilder.newJob(ClearLxcJob.class).
withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP).
usingJobData(new JobDataMap(new HashMap())).build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(job)
.usingJobData(new JobDataMap(new HashMap()))
.withIdentity(IDENTITY_LXC_GROUP)
.startNow().build();
// 触发器时间设定
Scheduler sched = schedulerFactoryBean.getScheduler();
try {
sched.scheduleJob(job, trigger);
// 启动
if (!sched.isShutdown()) {
sched.start();
}
}catch (Exception e){
log.error(e.getMessage());
}
* 容器所有bean都被defined 之后触发
*/
@Slf4j
public
class
RcListener
implements
ServletContextListener
{
@Component
public
class
RcApplicationRunner
implements
ApplicationRunner
{
/*任务组名*/
...
...
@@ -48,16 +34,17 @@ public class RcListener implements ServletContextListener {
@Override
public
void
contextDestroyed
(
ServletContextEvent
arg0
)
{
}
/**
* 执行任务
* @param arg0
*/
@Override
public
void
contextInitialized
(
ServletContextEvent
arg0
)
{
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
JobDetail
job
=
JobBuilder
.
newJob
(
ClearLxcJob
.
class
).
withIdentity
(
IDENTITY_LXC_GROUP
,
JOB_LXC_GROUP
).
usingJobData
(
new
JobDataMap
(
new
HashMap
())).
build
();
Trigger
trigger
=
TriggerBuilder
.
newTrigger
().
forJob
(
job
)
.
usingJobData
(
new
JobDataMap
(
new
HashMap
()))
.
withIdentity
(
IDENTITY_LXC_GROUP
)
.
startNow
().
build
();
// 触发器时间设定
/*触发器*/
TaskUtil
.
startSchedule
(
schedulerFactoryBean
.
getScheduler
(),
trigger
,
job
);
}
}
src/main/java/org/rcisoft/common/component/ApplicationContextHolder.java
View file @
e3270179
...
...
@@ -27,7 +27,7 @@ public class ApplicationContextHolder implements ApplicationContextAware {
}
/**
* Get
bean
by class
* Get
component
by class
*
* @param clazz
* @param <T>
...
...
@@ -38,7 +38,7 @@ public class ApplicationContextHolder implements ApplicationContextAware {
}
/**
* Get
bean
by class name
* Get
component
by class name
*
* @param name
* @param <T>
...
...
src/main/java/org/rcisoft/config/MvcConfig.java
View file @
e3270179
...
...
@@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSON;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.rcisoft.business.listener.RcListener
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.Result
;
import
org.rcisoft.core.result.ResultCode
;
import
org.rcisoft.core.util.ResultGenerator
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
...
...
@@ -241,14 +239,5 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
}
/**
* 监听器
* @return
*/
@Bean
public
ServletListenerRegistrationBean
servletListenerRegistrationBean
(){
ServletListenerRegistrationBean
servletListenerRegistrationBean
=
new
ServletListenerRegistrationBean
();
servletListenerRegistrationBean
.
setListener
(
new
RcListener
());
return
servletListenerRegistrationBean
;
}
}
src/main/java/org/rcisoft/core/util/TaskUtil.java
0 → 100644
View file @
e3270179
package
org
.
rcisoft
.
core
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.quartz.JobDetail
;
import
org.quartz.Scheduler
;
import
org.quartz.Trigger
;
import
java.io.Serializable
;
/**
* Created by lcy on 18/1/20.
*/
@Slf4j
public
class
TaskUtil
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
4513365435486468892L
;
/**
* 开启 schedule
* @param sched
* @param trigger
* @param job
* @return
*/
public
static
boolean
startSchedule
(
Scheduler
sched
,
Trigger
trigger
,
JobDetail
job
){
try
{
sched
.
scheduleJob
(
job
,
trigger
);
// 启动
if
(!
sched
.
isShutdown
())
{
sched
.
start
();
}
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
());
return
false
;
}
return
true
;
}
}
src/main/resources/application.yml
View file @
e3270179
spring
:
profiles
:
active
:
prod
\ No newline at end of file
active
:
dev
\ 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