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 {
case "sync":
return NewSync(conf)
case "fetch":
return NewFetch(conf)
case "today":
return NewToday(conf)
case "tomorrow":

View File

@ -10,29 +10,29 @@ import (
"git.ewintr.nl/gte/pkg/mstore"
)
type Sync struct {
syncer *process.Sync
type Fetch struct {
fetcher *process.Fetch
}
func NewSync(conf *configuration.Configuration) (*Sync, error) {
func NewFetch(conf *configuration.Configuration) (*Fetch, error) {
msgStore := mstore.NewIMAP(conf.IMAP())
remote := storage.NewRemoteRepository(msgStore)
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Sync{}, err
return &Fetch{}, err
}
syncer := process.NewSync(remote, local)
fetcher := process.NewFetch(remote, local)
return &Sync{
syncer: syncer,
return &Fetch{
fetcher: fetcher,
}, nil
}
func (s *Sync) Do() string {
result, err := s.syncer.Process()
func (s *Fetch) Do() string {
result, err := s.fetcher.Process()
if err != nil {
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 (
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
type Sync struct {
// Fetch fetches all tasks in regular folders from the remote repository and overwrites what is stored locally
type Fetch struct {
remote *storage.RemoteRepository
local storage.LocalRepository
}
type SyncResult struct {
type FetchResult struct {
Duration string `json:"duration"`
Count int `json:"count"`
}
func NewSync(remote *storage.RemoteRepository, local storage.LocalRepository) *Sync {
return &Sync{
func NewFetch(remote *storage.RemoteRepository, local storage.LocalRepository) *Fetch {
return &Fetch{
remote: remote,
local: local,
}
}
func (s *Sync) Process() (*SyncResult, error) {
func (s *Fetch) Process() (*FetchResult, error) {
start := time.Now()
tasks := []*task.Task{}
@ -41,7 +41,7 @@ func (s *Sync) Process() (*SyncResult, error) {
}
folderTasks, err := s.remote.FindAll(folder)
if err != nil {
return &SyncResult{}, fmt.Errorf("%w: %v", ErrSyncProcess, err)
return &FetchResult{}, fmt.Errorf("%w: %v", ErrFetchProcess, err)
}
for _, t := range folderTasks {
@ -50,10 +50,10 @@ func (s *Sync) Process() (*SyncResult, error) {
}
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(),
Count: len(tasks),
}, nil

View File

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