Skip to content

Commit

Permalink
update swap job of dispatching in order
Browse files Browse the repository at this point in the history
  • Loading branch information
jowenshaw committed May 14, 2021
1 parent b6be7b7 commit 778b11b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions worker/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ func StartSwapJob() {
for _, pairCfg := range tokens.GetTokenPairsConfig() {
AddSwapJob(pairCfg)
}

go startSwapinSwapJob()
go startSwapoutSwapJob()
}

// AddSwapJob add swap job
func AddSwapJob(pairCfg *tokens.TokenPairConfig) {
pairID := strings.ToLower(pairCfg.PairID)
swapinDcrmAddr := strings.ToLower(pairCfg.DestToken.DcrmAddress)
if _, exist := swapinTaskChanMap[swapinDcrmAddr]; !exist {
swapinTaskChanMap[swapinDcrmAddr] = make(chan *tokens.BuildTxArgs, swapChanSize)
Expand All @@ -52,15 +54,12 @@ func AddSwapJob(pairCfg *tokens.TokenPairConfig) {
swapoutTaskChanMap[swapoutDcrmAddr] = make(chan *tokens.BuildTxArgs, swapChanSize)
go processSwapTask(swapoutTaskChanMap[swapoutDcrmAddr])
}

go startSwapinSwapJob(pairID)
go startSwapoutSwapJob(pairID)
}

func startSwapinSwapJob(pairID string) {
func startSwapinSwapJob() {
logWorker("swap", "start swapin swap job")
for {
res, err := findSwapinsToSwap(pairID)
res, err := findSwapinsToSwap()
if err != nil {
logWorkerError("swapin", "find swapins error", err)
}
Expand All @@ -79,10 +78,10 @@ func startSwapinSwapJob(pairID string) {
}
}

func startSwapoutSwapJob(pairID string) {
func startSwapoutSwapJob() {
logWorker("swapout", "start swapout swap job")
for {
res, err := findSwapoutsToSwap(pairID)
res, err := findSwapoutsToSwap()
if err != nil {
logWorkerError("swapout", "find swapouts error", err)
}
Expand All @@ -101,16 +100,16 @@ func startSwapoutSwapJob(pairID string) {
}
}

func findSwapinsToSwap(pairID string) ([]*mongodb.MgoSwap, error) {
func findSwapinsToSwap() ([]*mongodb.MgoSwap, error) {
status := mongodb.TxNotSwapped
septime := getSepTimeInFind(maxDoSwapLifetime)
return mongodb.FindSwapinsWithPairIDAndStatus(pairID, status, septime)
return mongodb.FindSwapinsWithStatus(status, septime)
}

func findSwapoutsToSwap(pairID string) ([]*mongodb.MgoSwap, error) {
func findSwapoutsToSwap() ([]*mongodb.MgoSwap, error) {
status := mongodb.TxNotSwapped
septime := getSepTimeInFind(maxDoSwapLifetime)
return mongodb.FindSwapoutsWithPairIDAndStatus(pairID, status, septime)
return mongodb.FindSwapoutsWithStatus(status, septime)
}

func isSwapInBlacklist(swap *mongodb.MgoSwapResult) (isBlacked bool, err error) {
Expand Down

0 comments on commit 778b11b

Please sign in to comment.