Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nodemanager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Odysseus
nodemanager
Commits
f2d55c8b
Commit
f2d55c8b
authored
Feb 23, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
231eb8ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
20 deletions
+34
-20
service.go
server/service.go
+7
-2
workerManager.go
server/workerManager.go
+8
-5
workerstatu.go
server/workerstatu.go
+19
-13
No files found.
server/service.go
View file @
f2d55c8b
...
...
@@ -5,6 +5,7 @@ import (
"errors"
"github.com/odysseus/nodemanager/utils"
omanager
"github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
"strings"
)
var
(
...
...
@@ -45,7 +46,11 @@ func (n *NodeManagerService) DispatchTask(ctx context.Context, request *omanager
if
request
==
nil
{
return
nil
,
errors
.
New
(
"invalid request"
)
}
workerAddr
:=
request
.
Miner
mids
:=
strings
.
Split
(
request
.
Miner
,
"_"
)
if
len
(
mids
)
!=
2
{
return
nil
,
errors
.
New
(
"invalid miner"
)
}
workerAddr
:=
mids
[
0
]
worker
:=
n
.
node
.
wm
.
GetWorkerByAddr
(
workerAddr
)
if
worker
==
nil
{
return
nil
,
errors
.
New
(
"worker not found"
)
...
...
@@ -67,6 +72,6 @@ func (n *NodeManagerService) DispatchTask(ctx context.Context, request *omanager
res
:=
new
(
omanager
.
DispatchTaskResponse
)
res
.
TaskId
=
request
.
TaskData
.
TaskId
res
.
Miner
=
request
.
Mine
r
res
.
Miner
=
workerAdd
r
return
res
,
nil
}
server/workerManager.go
View file @
f2d55c8b
...
...
@@ -201,7 +201,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
})
.
Info
(
"exit manage worker"
)
worker
.
online
=
false
wm
.
InActiveWorker
(
worker
.
addr
)
wm
.
InActiveWorker
(
worker
)
}()
for
{
...
...
@@ -230,7 +230,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
deviceUsageTicker
.
Reset
(
time
.
Second
*
time
.
Duration
(
tickerConf
.
DeviceUsageTicker
))
}
if
time
.
Now
()
.
Unix
()
-
wm
.
GetHeartBeat
(
worker
.
uuid
)
>
int64
(
workerCheckDuration
.
Seconds
())
{
wm
.
InActiveWorker
(
worker
.
addr
)
wm
.
InActiveWorker
(
worker
)
// todo: remove worker
return
ErrHeartBeatExpired
}
...
...
@@ -326,9 +326,8 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
callback
=
func
(
err
error
)
bool
{
// remove task from cache.
worker
.
recentTask
.
Remove
(
result
.
TaskId
)
_
=
wm
.
AddWorkerSingle
(
worker
)
if
task
.
TaskKind
!=
odysseus
.
TaskKind_StandardTask
{
_
=
wm
.
AddWorkerSingle
(
worker
)
wm
.
Payment
(
task
)
}
return
true
...
...
@@ -447,6 +446,11 @@ func (wm *WorkerManager) handleWorkerMsg(worker *Worker) {
// addr is not change.
continue
}
if
worker
.
addr
!=
""
{
wm
.
InActiveWorker
(
worker
)
}
worker
.
addr
=
addr
if
worker
.
addr
!=
""
{
infoData
,
err
:=
json
.
Marshal
(
msg
.
DeviceInfo
.
Devices
)
...
...
@@ -462,7 +466,6 @@ func (wm *WorkerManager) handleWorkerMsg(worker *Worker) {
}
worker
.
deviceInfoHash
=
infoHash
[
:
]
}
wm
.
InActiveWorker
(
addr
)
wm
.
AddWorkerFirst
(
worker
)
wm
.
SetWorkerAddr
(
worker
,
worker
.
addr
)
}
...
...
server/workerstatu.go
View file @
f2d55c8b
...
...
@@ -2,6 +2,7 @@ package server
import
(
"context"
"fmt"
"github.com/odysseus/nodemanager/config"
log
"github.com/sirupsen/logrus"
"strconv"
...
...
@@ -10,7 +11,6 @@ import (
func
(
wm
*
WorkerManager
)
UpdateWorkerDeviceInfo
(
worker
*
Worker
,
deviceInfos
string
)
{
deviceInfoKey
:=
config
.
WORKER_DEVICE_INFO_PREFIX
+
worker
.
addr
wm
.
rdb
.
Set
(
context
.
Background
(),
deviceInfoKey
,
deviceInfos
,
0
)
}
func
(
wm
*
WorkerManager
)
AddWorkerFirst
(
worker
*
Worker
)
error
{
...
...
@@ -19,37 +19,43 @@ func (wm *WorkerManager) AddWorkerFirst(worker *Worker) error {
// add device to redis
priority
:=
0
_
=
device
// todo: set priority with device info.
if
err
:=
wm
.
rdb
.
RPush
(
context
.
Background
(),
config
.
WORKER_QUEUE_PREFIX
+
strconv
.
Itoa
(
priority
),
worker
.
addr
)
.
Err
();
err
!=
nil
{
if
err
:=
wm
.
rdb
.
RPush
(
context
.
Background
(),
config
.
WORKER_QUEUE_PREFIX
+
strconv
.
Itoa
(
priority
),
worker
Id
(
worker
)
)
.
Err
();
err
!=
nil
{
continue
}
}
// add worker to redis queue
if
err
:=
wm
.
rdb
.
SAdd
(
context
.
Background
(),
config
.
WORKER_STATUS_PREFIX
+
worker
.
addr
,
config
.
GetConfig
()
.
PublicEndpoint
())
.
Err
();
err
!=
nil
{
return
err
}
wm
.
ActiveWorker
(
worker
)
return
nil
}
func
(
wm
*
WorkerManager
)
AddWorkerSingle
(
worker
*
Worker
)
error
{
log
.
WithField
(
"worker"
,
worker
.
addr
)
.
Info
(
"add worker on back."
)
{
// add worker to redis
// add worker to redis
queue
priority
:=
0
if
err
:=
wm
.
rdb
.
RPush
(
context
.
Background
(),
config
.
WORKER_QUEUE_PREFIX
+
strconv
.
Itoa
(
priority
),
worker
.
addr
)
.
Err
();
err
!=
nil
{
if
err
:=
wm
.
rdb
.
RPush
(
context
.
Background
(),
config
.
WORKER_QUEUE_PREFIX
+
strconv
.
Itoa
(
priority
),
worker
Id
(
worker
)
)
.
Err
();
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"add worker back to queue failed."
)
}
}
// add worker to redis queue
if
err
:=
wm
.
rdb
.
SAdd
(
context
.
Background
(),
config
.
WORKER_STATUS_PREFIX
+
worker
.
addr
,
config
.
GetConfig
()
.
PublicEndpoint
())
.
Err
();
err
!=
nil
{
return
err
}
wm
.
ActiveWorker
(
worker
)
return
nil
}
func
(
wm
*
WorkerManager
)
ActiveWorker
(
worker
*
Worker
)
{
wm
.
rdb
.
SAdd
(
context
.
Background
(),
config
.
WORKER_STATUS_PREFIX
+
worker
.
addr
,
config
.
GetConfig
()
.
PublicEndpoint
())
wm
.
rdb
.
SAdd
(
context
.
Background
(),
workerStatusKey
(
worker
),
config
.
GetConfig
()
.
PublicEndpoint
())
}
func
(
wm
*
WorkerManager
)
InActiveWorker
(
worker
*
Worker
)
{
wm
.
rdb
.
SRem
(
context
.
Background
(),
workerStatusKey
(
worker
),
config
.
GetConfig
()
.
PublicEndpoint
())
}
func
workerStatusKey
(
w
*
Worker
)
string
{
id
:=
workerId
(
w
)
return
fmt
.
Sprintf
(
"%s_%s"
,
config
.
WORKER_STATUS_PREFIX
,
id
)
}
func
(
wm
*
WorkerManager
)
InActiveWorker
(
addr
string
)
{
wm
.
rdb
.
SRem
(
context
.
Background
(),
config
.
WORKER_STATUS_PREFIX
+
addr
,
config
.
GetConfig
()
.
PublicEndpoint
()
)
func
workerId
(
w
*
Worker
)
string
{
return
fmt
.
Sprintf
(
"%s_%d"
,
w
.
addr
,
w
.
uuid
)
}
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