rename sync to fetch

This commit is contained in:
Erik Winter 2021-09-03 07:12:16 +02:00
parent 86ad6cb0fb
commit 99b8476cdf
4 changed files with 24 additions and 24 deletions

View File

@ -31,8 +31,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
} }
switch cmd { switch cmd {
case "sync": case "fetch":
return NewSync(conf) return NewFetch(conf)
case "today": case "today":
return NewToday(conf) return NewToday(conf)
case "tomorrow": case "tomorrow":

View File

@ -10,29 +10,29 @@ import (
"git.ewintr.nl/gte/pkg/mstore" "git.ewintr.nl/gte/pkg/mstore"
) )
type Sync struct { type Fetch struct {
syncer *process.Sync fetcher *process.Fetch
} }
func NewSync(conf *configuration.Configuration) (*Sync, error) { func NewFetch(conf *configuration.Configuration) (*Fetch, error) {
msgStore := mstore.NewIMAP(conf.IMAP()) msgStore := mstore.NewIMAP(conf.IMAP())
remote := storage.NewRemoteRepository(msgStore) remote := storage.NewRemoteRepository(msgStore)
local, err := storage.NewSqlite(conf.Sqlite()) local, err := storage.NewSqlite(conf.Sqlite())
if err != nil { if err != nil {
return &Sync{}, err return &Fetch{}, err
} }
syncer := process.NewSync(remote, local) fetcher := process.NewFetch(remote, local)
return &Sync{ return &Fetch{
syncer: syncer, fetcher: fetcher,
}, nil }, nil
} }
func (s *Sync) Do() string { func (s *Fetch) Do() string {
result, err := s.syncer.Process() result, err := s.fetcher.Process()
if err != nil { if err != nil {
return format.FormatError(err) return format.FormatError(err)
} }
return fmt.Sprintf("synced %d tasks\n", result.Count) return fmt.Sprintf("fetched %d tasks\n", result.Count)
} }

View File

@ -10,28 +10,28 @@ import (
) )
var ( var (
ErrSyncProcess = errors.New("could not sync local repository") ErrFetchProcess = errors.New("could not fetch tasks")
) )
// Sync fetches all tasks in regular folders from the remote repository and overwrites what is stored locally // Fetch fetches all tasks in regular folders from the remote repository and overwrites what is stored locally
type Sync struct { type Fetch struct {
remote *storage.RemoteRepository remote *storage.RemoteRepository
local storage.LocalRepository local storage.LocalRepository
} }
type SyncResult struct { type FetchResult struct {
Duration string `json:"duration"` Duration string `json:"duration"`
Count int `json:"count"` Count int `json:"count"`
} }
func NewSync(remote *storage.RemoteRepository, local storage.LocalRepository) *Sync { func NewFetch(remote *storage.RemoteRepository, local storage.LocalRepository) *Fetch {
return &Sync{ return &Fetch{
remote: remote, remote: remote,
local: local, local: local,
} }
} }
func (s *Sync) Process() (*SyncResult, error) { func (s *Fetch) Process() (*FetchResult, error) {
start := time.Now() start := time.Now()
tasks := []*task.Task{} tasks := []*task.Task{}
@ -41,7 +41,7 @@ func (s *Sync) Process() (*SyncResult, error) {
} }
folderTasks, err := s.remote.FindAll(folder) folderTasks, err := s.remote.FindAll(folder)
if err != nil { if err != nil {
return &SyncResult{}, fmt.Errorf("%w: %v", ErrSyncProcess, err) return &FetchResult{}, fmt.Errorf("%w: %v", ErrFetchProcess, err)
} }
for _, t := range folderTasks { for _, t := range folderTasks {
@ -50,10 +50,10 @@ func (s *Sync) Process() (*SyncResult, error) {
} }
if err := s.local.SetTasks(tasks); err != nil { if err := s.local.SetTasks(tasks); err != nil {
return &SyncResult{}, fmt.Errorf("%w: %v", ErrSyncProcess, err) return &FetchResult{}, fmt.Errorf("%w: %v", ErrFetchProcess, err)
} }
return &SyncResult{ return &FetchResult{
Duration: time.Since(start).String(), Duration: time.Since(start).String(),
Count: len(tasks), Count: len(tasks),
}, nil }, nil

View File

@ -11,7 +11,7 @@ import (
"git.ewintr.nl/gte/pkg/mstore" "git.ewintr.nl/gte/pkg/mstore"
) )
func TestSyncProcess(t *testing.T) { func TestFetchProcess(t *testing.T) {
task1 := &task.Task{ task1 := &task.Task{
Id: "id1", Id: "id1",
Version: 1, Version: 1,
@ -35,7 +35,7 @@ func TestSyncProcess(t *testing.T) {
remote := storage.NewRemoteRepository(mstorer) remote := storage.NewRemoteRepository(mstorer)
local := storage.NewMemory() local := storage.NewMemory()
syncer := process.NewSync(remote, local) syncer := process.NewFetch(remote, local)
actResult, err := syncer.Process() actResult, err := syncer.Process()
test.OK(t, err) test.OK(t, err)
test.Equals(t, 2, actResult.Count) test.Equals(t, 2, actResult.Count)