Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
streamingUserPortrait
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
赵威
streamingUserPortrait
Commits
ee417a0d
Commit
ee417a0d
authored
Feb 07, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request type to Either
parent
efc8e8f8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
32 deletions
+49
-32
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+42
-29
Redis.scala
src/main/scala/com.gmei.up/utils/Redis.scala
+7
-3
No files found.
src/main/scala/com.gmei.up/utils/ES.scala
View file @
ee417a0d
...
...
@@ -63,47 +63,60 @@ object ES {
implicit
val
ec
:
scala.concurrent.ExecutionContext
=
scala
.
concurrent
.
ExecutionContext
.
global
def
request
(
req
:
SearchRequest
)
:
Future
[
IndexedSeq
[
Content
]]
=
{
def
request
(
req
:
SearchRequest
)
:
Either
[
Throwable
,
Future
[
IndexedSeq
[
Content
]
]]
=
{
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
// println(req.show)
client
.
execute
(
req
).
map
(
resp
=>
resp
.
result
.
to
[
Content
])
try
{
Right
(
client
.
execute
(
req
).
map
(
resp
=>
resp
.
result
.
to
[
Content
]))
}
catch
{
case
e
:
Throwable
=>
DingTalk
.
send
(
Map
(
"method"
->
"ES.request"
,
"error"
->
e
.
getStackTrace
.
mkString
(
"\n"
),
"request"
->
req
.
show
.
toString
),
contentType
=
"exception"
)
Left
(
e
)
}
// client.close()
}
def
test
(
diaryRequest
:
SearchRequest
,
tractateRequest
:
SearchRequest
,
answerRequest
:
SearchRequest
,
serviceDiaryReq
:
SearchRequest
)
=
{
// TODO read from config
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
//
def test(
//
diaryRequest: SearchRequest,
//
tractateRequest: SearchRequest,
//
answerRequest: SearchRequest,
//
serviceDiaryReq: SearchRequest
//
) = {
//
// TODO read from config
//
val client: ElasticClient = ESClient.create("172.16.52.33", 9200, "elastic", "gengmei!@#")
val
multiReq
=
multi
(
diaryRequest
,
tractateRequest
,
answerRequest
,
serviceDiaryReq
)
//
val multiReq = multi(
//
diaryRequest,
//
tractateRequest,
//
answerRequest,
//
serviceDiaryReq
//
)
println
(
multiReq
.
show
)
//
println(multiReq.show)
// TODO remove await
val
resp
=
client
.
execute
(
multiReq
).
await
//
// TODO remove await
//
val resp = client.execute(multiReq).await
// println(resp)
//
// println(resp)
val
a
=
resp
.
result
.
to
[
Content
]
//
val a = resp.result.to[Content]
println
(
"%%%%%%%%%%%"
)
println
(
a
.
size
)
a
.
foreach
{
x
=>
println
(
x
.
id
,
x
.
index
,
x
.
projects
)
}
println
(
"%%%%%%%%%%%"
)
//
println("%%%%%%%%%%%")
//
println(a.size)
//
a.foreach { x =>
//
println(x.id, x.index, x.projects)
//
}
//
println("%%%%%%%%%%%")
resp
}
//
resp
//
}
def
generateDiaryRequest
(
projects
:
List
[
String
],
...
...
src/main/scala/com.gmei.up/utils/Redis.scala
View file @
ee417a0d
...
...
@@ -24,15 +24,18 @@ object Redis {
}
def
save
(
content
F
:
Future
[
IndexedSeq
[
Content
]],
content
EitherFuture
:
Either
[
Throwable
,
Future
[
IndexedSeq
[
Content
]
]],
deviceId
:
String
,
contentType
:
String
,
timestampBegin
:
Long
)
:
Unit
=
{
val
key
=
s
"streaming:candidate:${contentType}:device_id:${deviceId}"
contentEitherFuture
match
{
case
Left
(
e
)
=>
e
.
printStackTrace
()
case
Right
(
contentFuture
)
=>
pRc4
.
withClient
{
client
=>
contentF
.
foreach
{
seq
=>
contentFuture
.
foreach
{
seq
=>
val
ids
=
seq
.
map
(
c
=>
c
.
id
)
if
(
ids
.
size
>
0
)
{
client
.
del
(
key
)
...
...
@@ -47,7 +50,7 @@ object Redis {
"method"
->
"Redis.save"
,
"deviceId"
->
deviceId
,
"contentType"
->
contentType
,
"streamTotalSeconds"
->
s
"${(Instant.now.getEpochSecond - timestampBegin)}
s"
"streamTotalSeconds"
->
s
"${(Instant.now.getEpochSecond * 1000 - timestampBegin * 1000)}m
s"
)
)
}
...
...
@@ -55,4 +58,5 @@ object Redis {
}
}
}
}
}
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