Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SooonerHotel
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
吴贤德
SooonerHotel
Commits
7951f0ce
Commit
7951f0ce
authored
5 years ago
by
吴贤德
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
中心服务:站点改造相关逻辑,播放日志表结构维护
parent
75479433
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
291 additions
and
4 deletions
+291
-4
Config.go
Services/CenterService/Config/Config.go
+27
-0
TableCreater.go
Services/CenterService/Controller/TableCreater.go
+34
-0
WasuChecker.go
Services/CenterService/Controller/WasuChecker.go
+20
-1
MediaListModel.go
Services/CenterService/Model/Pull/MediaListModel.go
+131
-0
SiteModel.go
Services/CenterService/Model/Pull/SiteModel.go
+64
-0
config.ini
Services/CenterService/config.ini
+7
-2
main.go
Services/CenterService/main.go
+8
-1
No files found.
Services/CenterService/Config/Config.go
View file @
7951f0ce
...
@@ -12,6 +12,7 @@ type Config struct {
...
@@ -12,6 +12,7 @@ type Config struct {
Ini
map
[
string
]
string
//Ini配置
Ini
map
[
string
]
string
//Ini配置
Sys
cmap
.
ConcurrentMap
//Sys配置
Sys
cmap
.
ConcurrentMap
//Sys配置
Sps
cmap
.
ConcurrentMap
//Sp配置
Sps
cmap
.
ConcurrentMap
//Sp配置
Sites
cmap
.
ConcurrentMap
//Site配置
}
}
var
config
*
Config
var
config
*
Config
...
@@ -24,6 +25,7 @@ func GetInstance() *Config {
...
@@ -24,6 +25,7 @@ func GetInstance() *Config {
initLogConfig
(
config
.
Ini
[
"log_path"
],
config
.
Ini
[
"log_filename"
],
24
*
30
*
time
.
Hour
,
1
*
time
.
Hour
)
initLogConfig
(
config
.
Ini
[
"log_path"
],
config
.
Ini
[
"log_filename"
],
24
*
30
*
time
.
Hour
,
1
*
time
.
Hour
)
config
.
Sys
=
cmap
.
New
()
config
.
Sys
=
cmap
.
New
()
config
.
Sps
=
cmap
.
New
()
config
.
Sps
=
cmap
.
New
()
config
.
Sites
=
cmap
.
New
()
})
})
return
config
return
config
...
@@ -76,3 +78,27 @@ func (this *Config) InitSpsConfig() error {
...
@@ -76,3 +78,27 @@ func (this *Config) InitSpsConfig() error {
}
}
return
err
return
err
}
}
func
(
this
*
Config
)
InitSitesConfig
()
error
{
url
:=
this
.
Ini
[
"api_conf_sites"
]
var
data
string
=
""
var
err
error
data
,
err
=
Request
.
Get
(
url
)
if
err
==
nil
{
jsonObj
,
err1
:=
simplejson
.
NewJson
([]
byte
(
data
))
if
err1
!=
nil
{
err
=
err1
}
else
{
sitesConf
,
err2
:=
jsonObj
.
Map
()
if
err2
!=
nil
{
err
=
err2
}
else
{
for
k
,
v
:=
range
sitesConf
{
//log.Infoln(k, v)
this
.
Sites
.
Set
(
k
,
v
)
}
}
}
}
return
err
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Services/CenterService/Controller/TableCreater.go
View file @
7951f0ce
package
Controller
package
Controller
import
(
"github.com/sirupsen/logrus"
"src/Common/Request"
"src/Config"
"time"
)
type
TableCreater
struct
{
Config
*
Config
.
Config
}
func
(
this
*
TableCreater
)
Start
()
{
go
func
()
{
START
:
n
:=
3600
*
6
this
.
createTable
()
time
.
Sleep
(
time
.
Duration
(
n
)
*
time
.
Second
)
goto
START
}()
}
func
(
this
*
TableCreater
)
createTable
()
{
url
:=
this
.
Config
.
Ini
[
"api_tb_playlog_create"
]
var
data
string
=
""
var
err
error
data
,
err
=
Request
.
Get
(
url
)
if
err
==
nil
{
logrus
.
Debugln
(
"TableCreater OK :"
,
data
)
}
else
{
logrus
.
Debugln
(
"TableCreater ERR :"
,
err
.
Error
())
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Services/CenterService/Controller/WasuChecker.go
View file @
7951f0ce
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
cmap
"github.com/orcaman/concurrent-map"
cmap
"github.com/orcaman/concurrent-map"
"src/Common/Unit"
"src/Common/Unit"
"src/Config"
"src/Config"
"src/Model/Pull"
"src/Model/Wasu"
"src/Model/Wasu"
"time"
"time"
)
)
...
@@ -20,7 +21,8 @@ func (this *WasuChecker) Start() {
...
@@ -20,7 +21,8 @@ func (this *WasuChecker) Start() {
START
:
START
:
s
,
ok
:=
this
.
Config
.
Sys
.
Get
(
"config_sp_check_seconds"
)
s
,
ok
:=
this
.
Config
.
Sys
.
Get
(
"config_sp_check_seconds"
)
if
ok
{
if
ok
{
this
.
check
()
//this.check()
this
.
checkSite
()
n
:=
Unit
.
Time2Seconds
(
s
.
(
string
))
+
10
n
:=
Unit
.
Time2Seconds
(
s
.
(
string
))
+
10
time
.
Sleep
(
time
.
Duration
(
n
)
*
time
.
Second
)
time
.
Sleep
(
time
.
Duration
(
n
)
*
time
.
Second
)
}
}
...
@@ -44,3 +46,19 @@ func (this *WasuChecker) check() {
...
@@ -44,3 +46,19 @@ func (this *WasuChecker) check() {
}
}
}
}
func
(
this
*
WasuChecker
)
checkSite
()
{
for
_
,
tmp
:=
range
this
.
Config
.
Sites
.
Items
()
{
site
:=
tmp
.
(
map
[
string
]
interface
{})
siteid
:=
site
[
"id"
]
.
(
string
);
if
!
this
.
queue
.
Has
(
siteid
)
{
this
.
queue
.
Set
(
siteid
,
"running"
)
//spModel := new(Wasu.SpModel)
//spModel.Config = this.Config
//spModel.Spid = spid
siteModel
:=
new
(
Pull
.
SiteModel
)
siteModel
.
Config
=
this
.
Config
siteModel
.
Siteid
=
siteid
go
siteModel
.
Start
()
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Services/CenterService/Model/Pull/MediaListModel.go
0 → 100644
View file @
7951f0ce
package
Pull
import
(
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"src/Common/Request"
"src/Config"
"strings"
"unsafe"
)
type
Media
struct
{
SiteId
string
`json:"site_id"`
Sps
[]
*
Sp
`json:"sps"`
JsonUrl
string
`json:"jsonUrl"`
NewsId
string
`json:"newsId"`
NewsName
string
`json:"newsName"`
NodeId
string
`json:"nodeId"`
NodeName
string
`json:"nodeName"`
// Md5 string `json:"md5"`
// PlayUrl string `json:"playUrl"`
}
type
Sp
struct
{
Spid
string
`json:"sp_id"`
PushMode
string
`json:"push_mode"`
//是否自动转推:0手动,1自动
}
type
MediaList
struct
{
CurrentPage
int
`json:"currentPage"`
PageNum
int
`json:"pageNum"`
PageSize
int
`json:"pageSize"`
Total
int
`json:"total"`
List
[]
*
Media
`json:"list"`
}
type
MediaListModel
struct
{
Config
*
Config
.
Config
Siteid
string
}
func
(
this
*
MediaListModel
)
FetchList
(
date
string
,
page
int
)
*
MediaList
{
wasu_api_incrementList
:=
""
config
,
ok
:=
this
.
Config
.
Sites
.
Get
(
this
.
Siteid
)
if
ok
{
conf
,
ok
:=
config
.
(
map
[
string
]
interface
{})
if
ok
{
wasu_api_incrementList
=
conf
[
"pull_api"
]
.
(
string
)
}
}
if
wasu_api_incrementList
==
""
{
logrus
.
Error
(
"PULL Site :"
,
this
.
Siteid
,
" 缺少配置项:pull_api"
)
}
mediaList
:=
new
(
MediaList
)
if
ok
{
url
:=
fmt
.
Sprintf
(
"%s?date=%s&page=%d"
,
wasu_api_incrementList
,
date
,
page
)
data
,
err
:=
Request
.
Get
(
url
)
if
err
==
nil
{
json
.
Unmarshal
([]
byte
(
data
),
mediaList
)
}
}
return
mediaList
}
func
(
this
*
MediaListModel
)
UpdateMediaList
(
mediaList
*
MediaList
)
bool
{
sps
:=
[]
*
Sp
{}
spids
:=
""
config
,
ok
:=
this
.
Config
.
Sites
.
Get
(
this
.
Siteid
)
if
ok
{
conf
,
ok
:=
config
.
(
map
[
string
]
interface
{})
if
ok
{
spids
=
conf
[
"spids"
]
.
(
string
)
}
}
spids
=
","
+
spids
+
","
for
_
,
tmp
:=
range
this
.
Config
.
Sps
.
Items
()
{
sp
:=
tmp
.
(
map
[
string
]
interface
{})
spid
:=
sp
[
"id"
]
.
(
string
);
idx
:=
strings
.
Index
(
spids
,
","
+
spid
+
","
)
if
idx
>
-
1
{
sp1
:=
new
(
Sp
)
sp1
.
Spid
=
spid
sp1
.
PushMode
=
sp
[
"wasu_incrementList_push_mode"
]
.
(
string
);
sps
=
append
(
sps
,
sp1
)
}
}
l
:=
len
(
mediaList
.
List
)
nOk
:=
0
for
_
,
media
:=
range
mediaList
.
List
{
media
.
SiteId
=
this
.
Siteid
media
.
Sps
=
sps
if
this
.
UpdateMedia
(
media
)
{
nOk
++
}
}
b
:=
false
if
nOk
==
l
{
b
=
true
}
logrus
.
Debugln
(
"UpdateMediaList : ok/total :"
,
nOk
,
"/"
,
l
)
return
b
}
func
(
this
*
MediaListModel
)
UpdateMedia
(
media
*
Media
)
bool
{
center_api_media_update
,
ok
:=
this
.
Config
.
Sys
.
Get
(
"center_api_media_update"
)
b
:=
false
if
ok
{
inData
,
_
:=
json
.
Marshal
(
media
)
//fmt.Printf("****** media_info : %v",media)
data
,
err
:=
Request
.
Post
(
center_api_media_update
.
(
string
),
*
(
*
string
)(
unsafe
.
Pointer
(
&
inData
)))
//data, err := Request.Post(center_api_media_update.(string), string(inData))
if
err
==
nil
{
if
data
==
"true"
{
b
=
true
}
}
}
return
b
}
This diff is collapsed.
Click to expand it.
Services/CenterService/Model/Pull/SiteModel.go
0 → 100644
View file @
7951f0ce
package
Pull
import
(
log
"github.com/sirupsen/logrus"
"src/Common/DateTime"
"src/Common/Unit"
"src/Config"
"time"
)
type
SiteModel
struct
{
Config
*
Config
.
Config
Siteid
string
}
func
(
this
*
SiteModel
)
Start
()
{
START
:
log
.
Infoln
(
"启动Site拉取增量媒资检测:"
,
this
.
Siteid
)
config
,
ok
:=
this
.
Config
.
Sites
.
Get
(
this
.
Siteid
)
n
:=
3600
if
ok
{
conf
,
ok
:=
config
.
(
map
[
string
]
interface
{})
if
ok
{
wasu_check_seconds
:=
conf
[
"check_seconds"
]
.
(
string
)
if
wasu_check_seconds
!=
""
{
n
=
Unit
.
Time2Seconds
(
wasu_check_seconds
)
}
this
.
pull
();
}
}
time
.
Sleep
(
time
.
Duration
(
n
)
*
time
.
Second
)
goto
START
}
func
(
this
*
SiteModel
)
pull
()
{
log
.
Infoln
(
"SiteModel.pull Starting..."
)
mediaModel
:=
new
(
MediaListModel
)
mediaModel
.
Config
=
this
.
Config
mediaModel
.
Siteid
=
this
.
Siteid
date
:=
DateTime
.
Format
(
"YYYYMMDD"
,
time
.
Now
())
//date="20190901"
//date="" //全量传空
mediaList
:=
mediaModel
.
FetchList
(
date
,
1
)
ok
:=
mediaModel
.
UpdateMediaList
(
mediaList
)
if
!
ok
{
log
.
Errorln
(
"mediaModel.UpdateMediaList err: date="
,
date
,
"page="
,
1
)
}
if
mediaList
!=
nil
{
pageNum
:=
mediaList
.
PageNum
if
pageNum
>=
2
{
for
page
:=
2
;
page
<=
pageNum
;
page
++
{
mediaList
:=
mediaModel
.
FetchList
(
date
,
page
)
ok
:=
mediaModel
.
UpdateMediaList
(
mediaList
)
if
!
ok
{
log
.
Errorln
(
"mediaModel.UpdateMediaList err: date="
,
date
,
"page="
,
page
)
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Services/CenterService/config.ini
View file @
7951f0ce
[debug]
[debug]
api_conf_sys
=
http://192.168.200.134:801/api/center/conf_sys #系统配置接口
api_conf_sys
=
http://192.168.200.134:801/api/center/conf_sys
api_conf_sps
=
http://192.168.200.134:801/api/center/conf_sps #合作方配置接口
api_conf_sps
=
http://192.168.200.134:801/api/center/conf_sps
api_conf_sites
=
http://192.168.200.134:801/api/center/conf_sites
api_tb_playlog_create
=
http://192.168.200.134:801/api/center/tb_playlog_create
log_path
=
./
log_path
=
./
log_filename
=
center_service.log
log_filename
=
center_service.log
[release]
[release]
api_conf_sys
=
http://api.hotel.wasu.tv/api/center/conf_sys #系统配置接口
api_conf_sys
=
http://api.hotel.wasu.tv/api/center/conf_sys #系统配置接口
api_conf_sps
=
http://api.hotel.wasu.tv/api/center/conf_sps #合作方配置接口
api_conf_sps
=
http://api.hotel.wasu.tv/api/center/conf_sps #合作方配置接口
api_conf_sites
=
http://api.hotel.wasu.tv/api/center/conf_sites #站点配置接口
api_tb_playlog_create
=
http://api.hotel.wasu.tv/api/center/tb_playlog_create #创建播放日志表
log_path
=
./
log_path
=
./
log_filename
=
center_service.log
log_filename
=
center_service.log
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Services/CenterService/main.go
View file @
7951f0ce
...
@@ -13,11 +13,17 @@ func main() {
...
@@ -13,11 +13,17 @@ func main() {
config
:=
Config
.
GetInstance
()
config
:=
Config
.
GetInstance
()
err1
:=
config
.
InitSysConfig
()
err1
:=
config
.
InitSysConfig
()
err2
:=
config
.
InitSpsConfig
()
err2
:=
config
.
InitSpsConfig
()
err3
:=
config
.
InitSitesConfig
()
//初始化成功
//初始化成功
if
err1
==
nil
&&
err2
==
nil
{
if
err1
==
nil
&&
err2
==
nil
&&
err3
==
nil
{
configCHK
:=
new
(
ConfigChecker
)
configCHK
:=
new
(
ConfigChecker
)
configCHK
.
Start
()
configCHK
.
Start
()
//创建播放日志表结果(6小时检查一次)
tbCreater
:=
new
(
TableCreater
)
tbCreater
.
Config
=
config
tbCreater
.
Start
()
//华数媒资拉取
//华数媒资拉取
wasuCHK
:=
new
(
WasuChecker
)
wasuCHK
:=
new
(
WasuChecker
)
wasuCHK
.
Config
=
config
wasuCHK
.
Config
=
config
...
@@ -30,6 +36,7 @@ func main() {
...
@@ -30,6 +36,7 @@ func main() {
}
else
{
}
else
{
log
.
Errorln
(
"初始化系统配置错误:"
,
err1
)
log
.
Errorln
(
"初始化系统配置错误:"
,
err1
)
log
.
Errorln
(
"初始化合作方配置错误:"
,
err2
)
log
.
Errorln
(
"初始化合作方配置错误:"
,
err2
)
log
.
Errorln
(
"初始化站点配置错误:"
,
err3
)
}
}
runtime
.
Goexit
()
runtime
.
Goexit
()
...
...
This diff is collapsed.
Click to expand it.
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