mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-08-31 23:35:46 +00:00
prevent per-user concurrent sync
This commit is contained in:
19
.drone.yml
19
.drone.yml
@@ -40,6 +40,7 @@ pipeline:
|
|||||||
publish_server_alpine:
|
publish_server_alpine:
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
repo: drone/drone
|
repo: drone/drone
|
||||||
|
dockerfile: Dockerfile.alpine
|
||||||
secrets: [ docker_username, docker_password ]
|
secrets: [ docker_username, docker_password ]
|
||||||
tag: [ alpine ]
|
tag: [ alpine ]
|
||||||
when:
|
when:
|
||||||
@@ -95,6 +96,24 @@ pipeline:
|
|||||||
branch: master
|
branch: master
|
||||||
event: push
|
event: push
|
||||||
|
|
||||||
|
release_server_alpine:
|
||||||
|
image: plugins/docker
|
||||||
|
repo: drone/drone
|
||||||
|
dockerfile: Dockerfile.alpine
|
||||||
|
secrets: [ docker_username, docker_password ]
|
||||||
|
tag: [ 0.8-alpine ]
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
release_agent_alpine:
|
||||||
|
image: plugins/docker
|
||||||
|
repo: drone/agent
|
||||||
|
dockerfile: Dockerfile.agent.alpine
|
||||||
|
secrets: [ docker_username, docker_password ]
|
||||||
|
tag: [ 0.8-alpine ]
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
release_server:
|
release_server:
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
repo: drone/drone
|
repo: drone/drone
|
||||||
|
@@ -6,6 +6,7 @@ package model
|
|||||||
type Limiter interface {
|
type Limiter interface {
|
||||||
LimitUser(*User) error
|
LimitUser(*User) error
|
||||||
LimitRepo(*User, *Repo) error
|
LimitRepo(*User, *Repo) error
|
||||||
|
LimitRepos(*User, []*Repo) []*Repo
|
||||||
LimitBuild(*User, *Repo, *Build) error
|
LimitBuild(*User, *Repo, *Build) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,5 +20,8 @@ func (NoLimit) LimitUser(*User) error { return nil }
|
|||||||
// LimitRepo is a no-op for limiting repo creation.
|
// LimitRepo is a no-op for limiting repo creation.
|
||||||
func (NoLimit) LimitRepo(*User, *Repo) error { return nil }
|
func (NoLimit) LimitRepo(*User, *Repo) error { return nil }
|
||||||
|
|
||||||
|
// LimitRepos is a no-op for limiting repository listings.
|
||||||
|
func (NoLimit) LimitRepos(user *User, repos []*Repo) []*Repo { return repos }
|
||||||
|
|
||||||
// LimitBuild is a no-op for limiting build creation.
|
// LimitBuild is a no-op for limiting build creation.
|
||||||
func (NoLimit) LimitBuild(*User, *Repo, *Build) error { return nil }
|
func (NoLimit) LimitBuild(*User, *Repo, *Build) error { return nil }
|
||||||
|
@@ -14,9 +14,10 @@ type Syncer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type syncer struct {
|
type syncer struct {
|
||||||
remote remote.Remote
|
remote remote.Remote
|
||||||
store store.Store
|
store store.Store
|
||||||
perms model.PermStore
|
perms model.PermStore
|
||||||
|
limiter model.Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncer) Sync(user *model.User) error {
|
func (s *syncer) Sync(user *model.User) error {
|
||||||
@@ -26,6 +27,10 @@ func (s *syncer) Sync(user *model.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.limiter != nil {
|
||||||
|
repos = s.limiter.LimitRepos(user, repos)
|
||||||
|
}
|
||||||
|
|
||||||
var perms []*model.Perm
|
var perms []*model.Perm
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
perm := model.Perm{
|
perm := model.Perm{
|
||||||
|
@@ -27,17 +27,20 @@ func GetFeed(c *gin.Context) {
|
|||||||
|
|
||||||
if time.Unix(user.Synced, 0).Add(time.Hour * 72).Before(time.Now()) {
|
if time.Unix(user.Synced, 0).Add(time.Hour * 72).Before(time.Now()) {
|
||||||
logrus.Debugf("sync begin: %s", user.Login)
|
logrus.Debugf("sync begin: %s", user.Login)
|
||||||
|
|
||||||
|
user.Synced = time.Now().Unix()
|
||||||
|
store.FromContext(c).UpdateUser(user)
|
||||||
|
|
||||||
sync := syncer{
|
sync := syncer{
|
||||||
remote: remote.FromContext(c),
|
remote: remote.FromContext(c),
|
||||||
store: store.FromContext(c),
|
store: store.FromContext(c),
|
||||||
perms: store.FromContext(c),
|
perms: store.FromContext(c),
|
||||||
|
limiter: Config.Services.Limiter,
|
||||||
}
|
}
|
||||||
if err := sync.Sync(user); err != nil {
|
if err := sync.Sync(user); err != nil {
|
||||||
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("sync complete: %s", user.Login)
|
logrus.Debugf("sync complete: %s", user.Login)
|
||||||
user.Synced = time.Now().Unix()
|
|
||||||
store.FromContext(c).UpdateUser(user)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,17 +71,19 @@ func GetRepos(c *gin.Context) {
|
|||||||
|
|
||||||
if flush || time.Unix(user.Synced, 0).Add(time.Hour*72).Before(time.Now()) {
|
if flush || time.Unix(user.Synced, 0).Add(time.Hour*72).Before(time.Now()) {
|
||||||
logrus.Debugf("sync begin: %s", user.Login)
|
logrus.Debugf("sync begin: %s", user.Login)
|
||||||
|
user.Synced = time.Now().Unix()
|
||||||
|
store.FromContext(c).UpdateUser(user)
|
||||||
|
|
||||||
sync := syncer{
|
sync := syncer{
|
||||||
remote: remote.FromContext(c),
|
remote: remote.FromContext(c),
|
||||||
store: store.FromContext(c),
|
store: store.FromContext(c),
|
||||||
perms: store.FromContext(c),
|
perms: store.FromContext(c),
|
||||||
|
limiter: Config.Services.Limiter,
|
||||||
}
|
}
|
||||||
if err := sync.Sync(user); err != nil {
|
if err := sync.Sync(user); err != nil {
|
||||||
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("sync complete: %s", user.Login)
|
logrus.Debugf("sync complete: %s", user.Login)
|
||||||
user.Synced = time.Now().Unix()
|
|
||||||
store.FromContext(c).UpdateUser(user)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user