Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
19be3a76
Commit
19be3a76
authored
May 25, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rollback change to chan
parent
edd89b0c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
45 deletions
+80
-45
main.go
main.go
+2
-1
process.go
pkg/app/process.go
+1
-0
rollback.go
pkg/app/rollback.go
+75
-0
node.go
routers/api/v1/node.go
+2
-44
No files found.
main.go
View file @
19be3a76
...
...
@@ -27,6 +27,7 @@ func init() {
var
tlog
=
log
.
New
(
"main"
,
"main.go"
)
var
serial
string
// @title Golang Gin API
// @version 1.0
// @description An example of gin
...
...
@@ -42,7 +43,7 @@ func main() {
//树莓派内置程序操作
go
app
.
PaiJob
(
time
.
NewTicker
(
time
.
Second
*
50
))
//go app.ClearLog(time.NewTicker(time.Hour*1))
go
app
.
RollbackJob
()
//上传统计树莓派信息
go
app
.
UploadInfo
(
time
.
NewTicker
(
time
.
Minute
*
10
))
...
...
pkg/app/process.go
View file @
19be3a76
...
...
@@ -892,3 +892,4 @@ func GetNodeUpdateStatus() bool {
}
return
false
}
pkg/app/rollback.go
0 → 100644
View file @
19be3a76
package
app
import
(
"time"
"chain33-pai/pkg/setting"
"bytes"
"os/exec"
"fmt"
"chain33-pai/service/pai_service"
)
var
RollChan
chan
bool
func
RollbackJob
()
{
for
{
if
value
,
err
:=
<-
RollChan
;
err
!=
nil
{
if
!
value
{
continue
}
err
:=
rollback
()
if
err
==
nil
{
tlog
.
Info
(
"rollback success"
,
"err"
,
nil
)
}
else
{
tlog
.
Error
(
"rollback fail "
,
"err"
,
err
)
}
}
time
.
Sleep
(
time
.
Second
*
1
)
}
}
func
rollback
()
error
{
BityuanFlag
=
true
_
,
err
:=
SafeCloseNode
()
if
err
!=
nil
{
BityuanFlag
=
false
return
err
}
var
pai
pai_service
.
Pai
err
=
pai
.
SetPai
()
if
err
!=
nil
{
tlog
.
Error
(
"SetPai"
,
"err"
,
err
)
BityuanFlag
=
false
return
err
}
if
pai
.
LocalLastHeight
==
0
{
tlog
.
Error
(
"LocalLastHeight"
,
"height"
,
pai
.
LocalLastHeight
)
BityuanFlag
=
false
return
err
}
rollheight
:=
pai
.
LocalLastHeight
-
1000
if
(
pai
.
LocalLastHeight
-
1000
)
<=
0
{
rollheight
=
1
}
time
.
Sleep
(
time
.
Second
*
2
)
tlog
.
Info
(
"rollback start"
,
"height"
,
pai
.
LocalLastHeight
,
"rollbackheight"
,
rollheight
)
var
buf
bytes
.
Buffer
path
:=
GetAbsPath
(
setting
.
BityuanSetting
.
Name
)
if
path
==
""
{
tlog
.
Error
(
"GetAbsPath"
,
"err"
,
"path not exists"
)
BityuanFlag
=
false
return
err
}
cmd
:=
exec
.
Command
(
path
+
"/"
+
setting
.
BityuanSetting
.
Name
,
"-rollback"
,
fmt
.
Sprintf
(
"%d"
,
rollheight
))
cmd
.
Stdout
=
&
buf
err
=
cmd
.
Run
()
if
err
!=
nil
{
BityuanFlag
=
false
return
err
}
tlog
.
Info
(
"rollback end"
,
"height"
,
pai
.
LocalLastHeight
,
"rollbackheight"
,
rollheight
)
BityuanFlag
=
false
return
nil
}
\ No newline at end of file
routers/api/v1/node.go
View file @
19be3a76
...
...
@@ -554,49 +554,6 @@ func Test(c *gin.Context) {
func
Rollback
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
app
.
BityuanFlag
=
true
_
,
err
:=
app
.
SafeCloseNode
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
var
pai
pai_service
.
Pai
err
=
pai
.
SetPai
()
if
err
!=
nil
{
tlog
.
Error
(
"SetPai"
,
"err"
,
err
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
if
pai
.
LocalLastHeight
==
0
{
tlog
.
Error
(
"LocalLastHeight"
,
"height"
,
pai
.
LocalLastHeight
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
rollheight
:=
pai
.
LocalLastHeight
-
1000
if
(
pai
.
LocalLastHeight
-
1000
)
<=
0
{
rollheight
=
1
}
time
.
Sleep
(
time
.
Second
*
2
)
tlog
.
Info
(
"rollback start"
,
"height"
,
pai
.
LocalLastHeight
,
"rollbackheight"
,
rollheight
)
var
buf
bytes
.
Buffer
path
:=
app
.
GetAbsPath
(
setting
.
BityuanSetting
.
Name
)
if
path
==
""
{
tlog
.
Error
(
"GetAbsPath"
,
"err"
,
"path not exists"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
return
}
cmd
:=
exec
.
Command
(
path
+
"/"
+
setting
.
BityuanSetting
.
Name
,
"-rollback"
,
fmt
.
Sprintf
(
"%d"
,
rollheight
))
cmd
.
Stdout
=
&
buf
err
=
cmd
.
Run
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
tlog
.
Info
(
"rollback end"
,
"height"
,
pai
.
LocalLastHeight
,
"rollbackheight"
,
rollheight
)
app
.
BityuanFlag
=
false
app
.
RollChan
<-
true
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"bityuan rollback"
)
}
\ 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