Pass replicationUrl and replicationInterval as parameters
Instead of reading them from the config, per consistency.master
parent
25f165d74e
commit
9e131ca116
|
@ -125,7 +125,7 @@ func Import() {
|
||||||
osmCache.Close()
|
osmCache.Close()
|
||||||
log.StopStep(step)
|
log.StopStep(step)
|
||||||
if config.ImportOptions.Diff {
|
if config.ImportOptions.Diff {
|
||||||
diffstate, err := state.FromPbf(config.ImportOptions.Read, config.BaseOptions.DiffStateBefore)
|
diffstate, err := state.FromPbf(config.ImportOptions.Read, config.BaseOptions.DiffStateBefore, config.BaseOptions.ReplicationUrl, config.BaseOptions.ReplicationInterval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("error parsing diff state form PBF", err)
|
log.Print("error parsing diff state form PBF", err)
|
||||||
} else if diffstate != nil {
|
} else if diffstate != nil {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/omniscale/imposm3/config"
|
|
||||||
"github.com/omniscale/imposm3/logging"
|
"github.com/omniscale/imposm3/logging"
|
||||||
"github.com/omniscale/imposm3/parser/pbf"
|
"github.com/omniscale/imposm3/parser/pbf"
|
||||||
)
|
)
|
||||||
|
@ -78,7 +77,7 @@ func FromOscGz(oscFile string) (*DiffState, error) {
|
||||||
return ParseFile(stateFile)
|
return ParseFile(stateFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromPbf(filename string, before time.Duration) (*DiffState, error) {
|
func FromPbf(filename string, before time.Duration, replicationUrl string, replicationInterval time.Duration) (*DiffState, error) {
|
||||||
pbfFile, err := pbf.NewParser(filename)
|
pbfFile, err := pbf.NewParser(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -94,18 +93,17 @@ func FromPbf(filename string, before time.Duration) (*DiffState, error) {
|
||||||
timestamp = fstat.ModTime()
|
timestamp = fstat.ModTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
replicationUrl := config.BaseOptions.ReplicationUrl
|
|
||||||
if replicationUrl == "" {
|
if replicationUrl == "" {
|
||||||
replicationUrl = "https://planet.openstreetmap.org/replication/minute/"
|
replicationUrl = "https://planet.openstreetmap.org/replication/minute/"
|
||||||
}
|
}
|
||||||
|
|
||||||
seq := estimateSequence(replicationUrl, timestamp)
|
seq := estimateSequence(replicationUrl, replicationInterval, timestamp)
|
||||||
if seq == 0 {
|
if seq == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// start earlier
|
// start earlier
|
||||||
seq -= int(before.Minutes() / config.BaseOptions.ReplicationInterval.Minutes())
|
seq -= int(math.Ceil(before.Minutes() / replicationInterval.Minutes()))
|
||||||
return &DiffState{Time: timestamp, Url: replicationUrl, Sequence: seq}, nil
|
return &DiffState{Time: timestamp, Url: replicationUrl, Sequence: seq}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +195,7 @@ func currentState(url string) (*DiffState, error) {
|
||||||
return Parse(resp.Body)
|
return Parse(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func estimateSequence(url string, timestamp time.Time) int {
|
func estimateSequence(url string, interval time.Duration, timestamp time.Time) int {
|
||||||
state, err := currentState(url)
|
state, err := currentState(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try a second time before failing
|
// try a second time before failing
|
||||||
|
@ -212,5 +210,5 @@ func estimateSequence(url string, timestamp time.Time) int {
|
||||||
|
|
||||||
behind := state.Time.Sub(timestamp)
|
behind := state.Time.Sub(timestamp)
|
||||||
// Sequence unit depends on replication interval (minute, hour, day).
|
// Sequence unit depends on replication interval (minute, hour, day).
|
||||||
return state.Sequence - int(math.Ceil(behind.Minutes() / config.BaseOptions.ReplicationInterval.Minutes()))
|
return state.Sequence - int(math.Ceil(behind.Minutes() / interval.Minutes()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFromPBF(t *testing.T) {
|
func TestFromPBF(t *testing.T) {
|
||||||
state, err := FromPbf("../../parser/pbf/monaco-20150428.osm.pbf", time.Hour*1)
|
state, err := FromPbf("../../parser/pbf/monaco-20150428.osm.pbf", time.Hour*1, "", time.Minute*1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue