Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror sync interval specified as duration string #1407

Merged
merged 14 commits into from
Apr 8, 2017

Conversation

cez81
Copy link
Contributor

@cez81 cez81 commented Mar 29, 2017

My attempt on solution for #1140. Would love to hear your comments if I'mon the right track?

Mirror.Interval is changed from int to string so that would require a migration script?

@strk
Copy link
Member

strk commented Mar 29, 2017

Changing a table column type would require a migration, yes.
Keeping the integer but changing semantic (for example: have them interpreted as minutes) would also require a migration.

I guess you'll want admins to be able to limit the minimum frequency of migrations (if allowed at all).

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 29, 2017
@cez81 cez81 changed the title [WIP] Sync interval specifed as duration string [WIP] Mirror sync interval specified as duration string Mar 29, 2017
Copy link
Member

@lunny lunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it should have a minimal duration, for example 1m ?

models/repo.go Outdated
@@ -811,11 +811,15 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
}

if opts.IsMirror {
duration, err := time.ParseDuration(setting.Mirror.DefaultInterval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compitable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just a note, time.ParseDuration accepts negative durations. This should be checked for.

@cez81
Copy link
Contributor Author

cez81 commented Mar 29, 2017

I have taken your comments on board and done a few changes.

  • Added a new setting mirror.MinInterval with 10 minutes as default
  • MinInterval must be >1 minute or defaults to 1 minute
  • DefaultInterval must be > MinInterval or defaults to 8h
  • Set Interval must be >MinInterval
  • Changed back to storing the interval as int in the database (store as time.Duration ie nanoseconds)
  • I use duration more to save me from parsing the duration string all the time

Ps. Haven't done anything with migration yet until settled on the other bits first.

if Mirror.DefaultInterval <= 0 {
Mirror.DefaultInterval = 24
sec = Cfg.Section("mirror")
Mirror.MinInterval = sec.Key("MIN_INTERVAL").MustDuration(time.Second * 55)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is time.Secdon * 55?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops they shouldn't be there. Removed as MustDuration will return 0 on error and that will be picked up with the following if cases.

@@ -903,8 +903,8 @@ please consider changing to GITEA_CUSTOM`)
}

sec = Cfg.Section("mirror")
Mirror.MinInterval = sec.Key("MIN_INTERVAL").MustDuration(time.Second * 55)
Mirror.DefaultInterval = sec.Key("DEFAULT_INTERVAL").MustDuration(time.Hour * 55)
Mirror.MinInterval = sec.Key("MIN_INTERVAL").MustDuration()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm somethings not right with this. Doesn't read default from built in app.ini

@cez81 cez81 changed the title [WIP] Mirror sync interval specified as duration string Mirror sync interval specified as duration string Mar 31, 2017
@lunny lunny added this to the 1.2.0 milestone Apr 6, 2017
@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 6, 2017
}
for _, mirror := range mirrors {
mirror.Interval = mirror.Interval * time.Hour
_, err := x.Id(mirror.ID).Cols("interval").Update(mirror)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may needs a transaction.

if form.Interval > 0 {
interval, err := time.ParseDuration(form.Interval)
if err != nil || interval < setting.Mirror.MinInterval {
ctx.Handle(500, "UpdateMirror", err)
Copy link
Member

@lunny lunny Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show a hint is better than give a 500.

@lunny
Copy link
Member

lunny commented Apr 6, 2017

Otherwise LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 6, 2017
}
}

if err := sess.Commit(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return sess.Commit()

is more cleaner.

@pgaskin
Copy link
Contributor

pgaskin commented Apr 8, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 8, 2017
@lunny lunny merged commit 54f0293 into go-gitea:master Apr 8, 2017
@cez81 cez81 deleted the mirror_interval branch April 8, 2017 16:12
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants