Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
automatic-test
Overview
Overview
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
钟涨钱
automatic-test
Commits
240fea95
Commit
240fea95
authored
Sep 09, 2021
by
朽木不可雕也
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backup
parent
98fece20
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
barrage-crawler-server/src/main/java/com/zhiweidata/automatictest/barragecrawlerserver/exporttasks/ExportTaskJob.java
+27
-2
No files found.
barrage-crawler-server/src/main/java/com/zhiweidata/automatictest/barragecrawlerserver/exporttasks/ExportTaskJob.java
View file @
240fea95
...
@@ -9,6 +9,7 @@ import com.zhiweidata.automatictest.barragecrawlerserver.entity.BarrageExportRes
...
@@ -9,6 +9,7 @@ import com.zhiweidata.automatictest.barragecrawlerserver.entity.BarrageExportRes
import
com.zhiweidata.automatictest.barragecrawlerserver.entity.ServerResponseMessage
;
import
com.zhiweidata.automatictest.barragecrawlerserver.entity.ServerResponseMessage
;
import
com.zhiweidata.automatictest.barragecrawlerserver.mapper.BarrageExportResultMapper
;
import
com.zhiweidata.automatictest.barragecrawlerserver.mapper.BarrageExportResultMapper
;
import
com.zhiweidata.automatictest.barragecrawlerserver.mapper.ServerResponseMessageMapper
;
import
com.zhiweidata.automatictest.barragecrawlerserver.mapper.ServerResponseMessageMapper
;
import
com.zhiweidata.automatictest.barragecrawlerserver.util.TimeUtil
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -27,13 +28,17 @@ import org.apache.ibatis.session.SqlSession;
...
@@ -27,13 +28,17 @@ import org.apache.ibatis.session.SqlSession;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.quartz.Job
;
import
org.quartz.Job
;
import
org.quartz.JobDataMap
;
import
org.quartz.JobDataMap
;
import
org.quartz.JobDetail
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.SchedulerException
;
import
org.quartz.SchedulerException
;
import
org.quartz.Trigger
;
import
org.quartz.TriggerBuilder
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
BARRAGE_COLLECTION_TASK_JOB_KEY
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
BARRAGE_COLLECTION_TASK_JOB_KEY
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
CACHE_DIR
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
CACHE_DIR
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
TASK_URL
;
import
static
com
.
zhiweidata
.
automatictest
.
barragecrawlerserver
.
config
.
BaseConfig
.
TASK_URL
;
import
static
com
.
zhiweidata
.
automatictest
.
publics
.
BeanContainer
.
HTTP_CLIENT
;
import
static
com
.
zhiweidata
.
automatictest
.
publics
.
BeanContainer
.
HTTP_CLIENT
;
import
static
com
.
zhiweidata
.
automatictest
.
publics
.
BeanContainer
.
SCHEDULER
;
import
static
com
.
zhiweidata
.
automatictest
.
publics
.
BeanContainer
.
SQL_SESSION_FACTORY
;
import
static
com
.
zhiweidata
.
automatictest
.
publics
.
BeanContainer
.
SQL_SESSION_FACTORY
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
isNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
...
@@ -47,9 +52,14 @@ import static java.util.Objects.requireNonNull;
...
@@ -47,9 +52,14 @@ import static java.util.Objects.requireNonNull;
* @ide IntelliJ IDEA
* @ide IntelliJ IDEA
*/
*/
@Slf4j
@Slf4j
@SuppressWarnings
(
"JavaDoc"
)
@SuppressWarnings
(
{
"JavaDoc"
,
"GrazieInspection"
}
)
public
class
ExportTaskJob
implements
Job
{
public
class
ExportTaskJob
implements
Job
{
/**
/**
* 作业对象
*/
private
JobDetail
detail
;
/**
* 1. 使用任务的 name 作为关键词,请求接口,获得对应任务的任务ID
* 1. 使用任务的 name 作为关键词,请求接口,获得对应任务的任务ID
* 2. 根据获得的任务ID,尝试从弹幕导出接口,导出弹幕
* 2. 根据获得的任务ID,尝试从弹幕导出接口,导出弹幕
* 3. 判断服务的响应是 excel 文件,还是 application/json
* 3. 判断服务的响应是 excel 文件,还是 application/json
...
@@ -61,6 +71,7 @@ public class ExportTaskJob implements Job {
...
@@ -61,6 +71,7 @@ public class ExportTaskJob implements Job {
try
{
try
{
JobDataMap
jobDataMap
=
requireNonNull
(
context
.
getMergedJobDataMap
());
JobDataMap
jobDataMap
=
requireNonNull
(
context
.
getMergedJobDataMap
());
BarrageCollectionTestTask
collectionTask
=
(
BarrageCollectionTestTask
)
requireNonNull
(
jobDataMap
.
get
(
BARRAGE_COLLECTION_TASK_JOB_KEY
));
BarrageCollectionTestTask
collectionTask
=
(
BarrageCollectionTestTask
)
requireNonNull
(
jobDataMap
.
get
(
BARRAGE_COLLECTION_TASK_JOB_KEY
));
this
.
detail
=
context
.
getJobDetail
();
this
.
export
(
collectionTask
);
this
.
export
(
collectionTask
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
...
@@ -91,7 +102,7 @@ public class ExportTaskJob implements Job {
...
@@ -91,7 +102,7 @@ public class ExportTaskJob implements Job {
/**
/**
* 下载excel文件,并检查excel文件
* 下载excel文件,并检查excel文件
*/
*/
private
void
checkFile
(
@NotNull
BarrageCollectionInfo
collectionInfo
)
throws
IOException
{
private
void
checkFile
(
@NotNull
BarrageCollectionInfo
collectionInfo
)
throws
IOException
,
SchedulerException
{
String
url
=
TASK_URL
+
"/"
+
collectionInfo
.
getId
()
+
"/barrage"
;
String
url
=
TASK_URL
+
"/"
+
collectionInfo
.
getId
()
+
"/barrage"
;
HttpGet
get
=
new
HttpGet
(
url
);
HttpGet
get
=
new
HttpGet
(
url
);
HttpResponse
response
=
HTTP_CLIENT
.
execute
(
get
);
HttpResponse
response
=
HTTP_CLIENT
.
execute
(
get
);
...
@@ -101,6 +112,9 @@ public class ExportTaskJob implements Job {
...
@@ -101,6 +112,9 @@ public class ExportTaskJob implements Job {
ServerResponseMessage
responseMessage
=
jsonMapper
.
readValue
(
response
.
getEntity
().
getContent
(),
ServerResponseMessage
.
class
);
ServerResponseMessage
responseMessage
=
jsonMapper
.
readValue
(
response
.
getEntity
().
getContent
(),
ServerResponseMessage
.
class
);
log
.
info
(
responseMessage
.
getMessage
());
log
.
info
(
responseMessage
.
getMessage
());
responseMessage
.
setName
(
collectionInfo
.
getName
());
responseMessage
.
setName
(
collectionInfo
.
getName
());
// 处理409资源冲突
this
.
conflict
(
responseMessage
);
// 保存响应
this
.
saveResponseMessage
(
responseMessage
);
this
.
saveResponseMessage
(
responseMessage
);
}
else
{
}
else
{
final
File
cacheDir
=
new
File
(
CACHE_DIR
,
collectionInfo
.
getId
());
final
File
cacheDir
=
new
File
(
CACHE_DIR
,
collectionInfo
.
getId
());
...
@@ -193,4 +207,15 @@ public class ExportTaskJob implements Job {
...
@@ -193,4 +207,15 @@ public class ExportTaskJob implements Job {
resultMapper
.
insert
(
exportResult
);
resultMapper
.
insert
(
exportResult
);
}
}
}
}
/**
* 处理409资源冲突,随机一个时间再导出一次
*/
private
void
conflict
(
@NotNull
ServerResponseMessage
responseMessage
)
throws
SchedulerException
{
if
(
responseMessage
.
getCode
()
!=
409
)
return
;
TriggerBuilder
<
Trigger
>
triggerBuilder
=
TriggerBuilder
.
newTrigger
();
triggerBuilder
.
withDescription
(
"导出弹幕测试"
);
triggerBuilder
.
startAt
(
TimeUtil
.
randmoDate
(
2
));
SCHEDULER
.
scheduleJob
(
this
.
detail
,
triggerBuilder
.
build
());
}
}
}
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