add -diff-state-before option to set initial diff sequence before

Oliver Tonnhofer 2014-09-15 14:07:27 +02:00
parent 1e4a6063f2
commit 44be47583b
3 changed files with 7 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"log"
"os"
"time"
)
type Config struct {
@ -135,6 +136,7 @@ type _ImportOptions struct {
DeployProduction bool
RevertDeploy bool
RemoveBackup bool
DiffStateBefore time.Duration
}
var BaseOptions = _BaseOptions{}
@ -183,6 +185,7 @@ func init() {
ImportFlags.BoolVar(&ImportOptions.DeployProduction, "deployproduction", false, "deploy production")
ImportFlags.BoolVar(&ImportOptions.RevertDeploy, "revertdeploy", false, "revert deploy to production")
ImportFlags.BoolVar(&ImportOptions.RemoveBackup, "removebackup", false, "remove backups from deploy")
ImportFlags.DurationVar(&ImportOptions.DiffStateBefore, "diff-state-before", 2*time.Hour, "set initial diff sequence before")
}
func ParseImport(args []string) {

View File

@ -79,7 +79,7 @@ func ParseFromOsc(oscFile string) (*DiffState, error) {
return ParseFile(stateFile)
}
func FromPbf(pbfFile *pbf.Pbf) *DiffState {
func FromPbf(pbfFile *pbf.Pbf, before time.Duration) *DiffState {
var timestamp time.Time
if pbfFile.Header.Time.Unix() != 0 {
timestamp = pbfFile.Header.Time
@ -99,8 +99,8 @@ func FromPbf(pbfFile *pbf.Pbf) *DiffState {
return nil
}
// start two hours earlier
seq -= 120
// start earlier
seq -= int32(before.Minutes())
return &DiffState{Time: timestamp, Url: replicationUrl, Sequence: seq}
}

View File

@ -123,7 +123,7 @@ func Import() {
osmCache.Close()
log.StopStep(step)
if config.ImportOptions.Diff {
diffstate := state.FromPbf(pbfFile)
diffstate := state.FromPbf(pbfFile, config.ImportOptions.DiffStateBefore)
if diffstate != nil {
os.MkdirAll(config.BaseOptions.DiffDir, 0755)
err := diffstate.WriteToFile(path.Join(config.BaseOptions.DiffDir, "last.state.txt"))