Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pdstask
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
曲欣亮
pdstask
Commits
a1e2f276
Commit
a1e2f276
authored
Nov 30, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X
parent
bdad5e3a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
118 deletions
+108
-118
EmailServiceTest.java
src/main/java/com/egolm/pds/EmailServiceTest.java
+1
-1
MailObject.java
src/main/java/com/egolm/pds/bean/MailObject.java
+0
-24
ProductsTask.java
src/main/java/com/egolm/pds/schedule/ProductsTask.java
+79
-58
EmailService.java
src/main/java/com/egolm/pds/service/EmailService.java
+28
-35
No files found.
src/main/java/com/egolm/pds/EmailServiceTest.java
View file @
a1e2f276
...
...
@@ -20,7 +20,7 @@ public class EmailServiceTest {
@Test
public
void
sendEmailTest
()
{
try
{
service
.
sendForsync
(
"测试邮件"
,
"测试邮件"
);
service
.
sendForsync
(
0
,
"测试邮件"
,
"测试邮件"
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
...
...
src/main/java/com/egolm/pds/bean/MailObject.java
deleted
100644 → 0
View file @
bdad5e3a
package
com
.
egolm
.
pds
.
bean
;
public
class
MailObject
{
private
String
subject
;
private
String
content
;
public
String
getSubject
()
{
return
subject
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setSubject
(
String
subject
)
{
this
.
subject
=
subject
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
}
src/main/java/com/egolm/pds/schedule/ProductsTask.java
View file @
a1e2f276
package
com
.
egolm
.
pds
.
schedule
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
...
...
@@ -49,6 +51,8 @@ public class ProductsTask {
private
void
executeUpdateTask
()
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
authKey
,
authValue
);
List
<
PdsErrDetail
>
errs
=
new
ArrayList
<
PdsErrDetail
>();
try
{
while
(
true
)
{
String
responseBody
=
HttpUtil
.
get
(
urlQuery
,
headers
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
responseBody
);
...
...
@@ -106,10 +110,27 @@ public class ProductsTask {
pdsService
.
savePdsProduct
(
transactionId
,
productMap
);;
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
emailService
.
sendForasync
(
"PDS TASK ERROR"
,
productJsonObject
.
toJSONString
(),
e
);
PdsErrDetail
err
=
new
PdsErrDetail
(
JSON
.
toJSONString
(
productJsonObject
),
e
);
errs
.
add
(
err
);
}
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
PdsErrDetail
err
=
new
PdsErrDetail
(
null
,
e
);
errs
.
add
(
err
);
}
finally
{
emailService
.
sendPdsErrorDetails
(
"PDS TASK ERROR"
,
errs
);
}
}
public
static
class
PdsErrDetail
{
public
final
String
data
;
public
final
Throwable
e
;
public
PdsErrDetail
(
String
data
,
Throwable
e
)
{
this
.
data
=
data
;
this
.
e
=
e
;
}
}
...
...
src/main/java/com/egolm/pds/service/EmailService.java
View file @
a1e2f276
...
...
@@ -2,54 +2,35 @@ package com.egolm.pds.service;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.MailUtil
;
import
com.egolm.pds.bean.MailObject
;
import
com.egolm.pds.bean.MailConfig
;
import
com.egolm.pds.
utils.ThrowableUt
il
;
import
com.egolm.pds.
schedule.ProductsTask.PdsErrDeta
il
;
@Component
public
class
EmailService
{
@Autowired
private
MailConfig
config
;
private
static
final
Log
log
=
LogFactory
.
getLog
(
EmailService
.
class
);
private
static
final
LinkedBlockingQueue
<
MailObject
>
queue
=
new
LinkedBlockingQueue
<
MailObject
>();
public
void
sendForasync
(
String
subject
,
String
content
,
Throwable
e
)
{
StringBuffer
stackString
=
ThrowableUtil
.
toStackString
(
e
);
public
void
sendPdsErrorDetails
(
String
subject
,
List
<
PdsErrDetail
>
errs
)
{
String
timeString
=
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
MailObject
emailObject
=
new
MailObject
();
emailObject
.
setSubject
(
subject
);
emailObject
.
setContent
(
"<pre>"
+
timeString
+
"\r\n"
+
subject
+
"\r\n"
+
content
+
"\r\n"
+
stackString
.
toString
()
+
"</pre>"
);
queue
.
add
(
emailObject
);
}
@Scheduled
(
initialDelay
=
5000
,
fixedRate
=
Long
.
MAX_VALUE
)
private
void
exec
()
{
while
(
true
)
{
MailObject
obj
=
null
;
try
{
obj
=
queue
.
take
();
this
.
sendForsync
(
obj
.
getSubject
(),
obj
.
getContent
());
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
if
(
obj
!=
null
)
{
queue
.
add
(
obj
);
}
}
StringBuffer
bodyString
=
new
StringBuffer
();
bodyString
.
append
(
timeString
).
append
(
System
.
lineSeparator
());
for
(
PdsErrDetail
err:
errs
)
{
bodyString
.
append
(
err
.
data
).
append
(
System
.
lineSeparator
());
bodyString
.
append
(
err
.
e
.
getMessage
()).
append
(
System
.
lineSeparator
());
}
bodyString
.
append
(
System
.
lineSeparator
()).
append
(
System
.
lineSeparator
()).
append
(
System
.
lineSeparator
());
this
.
sendForsync
(
5
,
subject
,
"<pre>"
+
bodyString
.
toString
()
+
"</pre>"
);
}
public
void
sendForsync
(
String
subject
,
String
content
)
{
public
void
sendForsync
(
int
tryCount
,
String
subject
,
String
content
)
{
try
{
String
host
=
config
.
getHost
();
Integer
port
=
config
.
getPort
();
String
username
=
config
.
getUsername
();
...
...
@@ -57,6 +38,18 @@ public class EmailService {
String
from
=
config
.
getFrom
();
List
<
String
>
to
=
config
.
getTo
();
MailUtil
.
sendBySmtp
(
host
,
port
,
true
,
username
,
password
,
from
,
subject
,
content
,
null
,
to
.
toArray
(
new
String
[
to
.
size
()]));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
if
(
tryCount
>
0
)
{
try
{
Thread
.
sleep
(
1000L
*
60
*
5
);
}
catch
(
InterruptedException
e1
)
{
e1
.
printStackTrace
();
}
this
.
sendForsync
(--
tryCount
,
subject
,
content
);
}
}
}
}
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