forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cockroachdb#9 from crowdflux/himanshu-github
sync all method in feedline repo
- Loading branch information
Showing
15 changed files
with
433 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package feed_line_repo | ||
|
||
import ( | ||
"github.com/crowdflux/angel/app/DAL/clients/postgres" | ||
"github.com/crowdflux/angel/app/models" | ||
"github.com/crowdflux/angel/app/models/uuid" | ||
"github.com/crowdflux/angel/app/plog" | ||
"gopkg.in/mgo.v2/bson" | ||
) | ||
|
||
func SyncAll() { | ||
|
||
inpQ := NewInputQueue() | ||
|
||
existingQFlus := []feedLineInputModel{} | ||
|
||
err := inpQ.mgo.C("feedline_input").Find(bson.M{}).All(&existingQFlus) | ||
if err != nil { | ||
plog.Error("feedline", err) | ||
return | ||
} | ||
|
||
plog.Info("existingQFlus", len(existingQFlus)) | ||
|
||
fluRepo := fluRepo{ | ||
Db: postgres.GetPostgresClient(), | ||
} | ||
|
||
flus := []models.FeedLineUnit{} | ||
|
||
_, err = fluRepo.Db.Select(&flus, "SELECT * FROM feed_line") | ||
if err != nil { | ||
plog.Error("feedline", err) | ||
return | ||
} | ||
|
||
plog.Info("flus", len(flus)) | ||
|
||
//flusToUpdate := []feedLineInputModel{} | ||
flusToInsert := []interface{}{} | ||
|
||
for _, eflu := range existingQFlus { | ||
|
||
if _, ok := existsInList(flus, eflu.ID); !ok { | ||
|
||
f := eflu.FeedLineUnit | ||
|
||
f.Build = models.JsonF{ | ||
"fail": true, | ||
} | ||
flusToInsert = append(flusToInsert, &f) | ||
} | ||
} | ||
|
||
//for _, f := range flusToInsert { | ||
// plog.Info("flusToInsert", f.(*models.FeedLineUnit).ID) | ||
// | ||
//} | ||
|
||
err = fluRepo.Db.Insert(flusToInsert...) | ||
if err != nil { | ||
plog.Error("feedline", err) | ||
return | ||
} | ||
|
||
plog.Info("extra", len(flusToInsert), " new flus inserted") | ||
|
||
/* | ||
err = inpQ.mgo.C("feedline_input").Insert(flusToInsert...) | ||
if err != nil { | ||
plog.Error("feedline", err) | ||
} | ||
for _, updateFlu := range flusToUpdate { | ||
err = inpQ.mgo.C("feedline_input").UpdateId(updateFlu.ID, updateFlu) | ||
if err != nil { | ||
plog.Error("feedline", err, updateFlu) | ||
} | ||
}*/ | ||
} | ||
|
||
func existsInList(list []models.FeedLineUnit, toFindId uuid.UUID) (*models.FeedLineUnit, bool) { | ||
for _, elem := range list { | ||
if elem.ID == toFindId { | ||
|
||
plog.Info("asd", elem.ID) | ||
return &elem, true | ||
} | ||
} | ||
return nil, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package feed_line | ||
|
||
import ( | ||
"github.com/crowdflux/angel/app/models/uuid" | ||
"sync" | ||
) | ||
|
||
type Bf struct { | ||
mtx sync.RWMutex | ||
fluMap map[uuid.UUID]FLU | ||
} | ||
|
||
func NewBuffer() Bf { | ||
return Bf{fluMap: make(map[uuid.UUID]FLU)} | ||
} | ||
|
||
// RLock is read lock i.e. either multiple reads | ||
// or single write can happen at a time | ||
func (b *Bf) Get(id uuid.UUID) (FLU, bool) { | ||
b.mtx.RLock() | ||
defer b.mtx.RUnlock() | ||
|
||
flu, ok := b.fluMap[id] | ||
return flu, ok | ||
} | ||
|
||
// Write lock part of the read write lock | ||
func (b *Bf) Save(flu FLU) { | ||
b.mtx.Lock() | ||
defer b.mtx.Unlock() | ||
|
||
b.fluMap[flu.ID] = flu | ||
} | ||
|
||
func (b *Bf) GetAll() map[uuid.UUID]FLU { | ||
b.mtx.RLock() | ||
defer b.mtx.RUnlock() | ||
|
||
return b.fluMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.