From 38856c9b399c78b678ec163f0075957e4b833b00 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 28 Sep 2021 05:05:57 +0000 Subject: [PATCH] Remove EverySeconds(), reduce rate limit --- client/client.go | 2 +- main.go | 21 +++++++-------------- rules/rules.go | 30 +++++++++--------------------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/client/client.go b/client/client.go index 0886413..e0f7c5a 100644 --- a/client/client.go +++ b/client/client.go @@ -38,7 +38,7 @@ type nextPage struct { func NewClient(token string) *Client { c := &Client{ client: &http.Client{}, - rateLimit: NewRateLimitPerMinute(1500, 1500), + rateLimit: NewRateLimitPerMinute(600, 10), concurrencyLimitRead: NewConcurrencyLimit(50), concurrencyLimitWrite: NewConcurrencyLimit(15), } diff --git a/main.go b/main.go index ec807f7..fe2bf81 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,7 @@ package main import . "github.com/firestuff/automana/rules" func main() { - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Meetings", "Tonight", "Upcoming", "Later", "Someday"). OnlyIncomplete(). DueInDays(0). @@ -12,8 +11,7 @@ func main() { PrintTasks(). MoveToMyTasksSection("Today") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Meetings", "Maybe Today", "Upcoming", "Later", "Someday"). OnlyIncomplete(). DueInDays(0). @@ -21,8 +19,7 @@ func main() { PrintTasks(). MoveToMyTasksSection("Tonight") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Maybe Today", "Tonight", "Upcoming", "Later", "Someday"). OnlyIncomplete(). DueInDays(0). @@ -30,8 +27,7 @@ func main() { PrintTasks(). MoveToMyTasksSection("Meetings") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Meetings", "Maybe Today", "Tonight", "Later", "Someday"). OnlyIncomplete(). DueInAtLeastDays(1). @@ -39,24 +35,21 @@ func main() { PrintTasks(). MoveToMyTasksSection("Upcoming") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Meetings", "Maybe Today", "Tonight", "Upcoming", "Someday"). OnlyIncomplete(). DueInAtLeastDays(8). PrintTasks(). MoveToMyTasksSection("Later") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Today", "Meetings", "Tonight", "Upcoming", "Later"). OnlyIncomplete(). WithoutDue(). PrintTasks(). MoveToMyTasksSection("Someday") - EverySeconds(30). - InWorkspace("flamingcow.io"). + InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Meetings", "Maybe Today", "Tonight", "Upcoming", "Later", "Someday"). OnlyIncomplete(). WithUnlinkedURL(). diff --git a/rules/rules.go b/rules/rules.go index 543c2e1..8b096a3 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -16,8 +16,7 @@ type taskFilter func(*client.WorkspaceClient, *client.Task) (bool, error) type workspaceClientGetter func(*client.Client) (*client.WorkspaceClient, error) type periodic struct { - period int - done chan bool + done chan bool workspaceClientGetter workspaceClientGetter queryMutators []queryMutator @@ -27,18 +26,6 @@ type periodic struct { var periodics = []*periodic{} -// TODO: Remove this, as it's now ignored -func EverySeconds(seconds int) *periodic { - ret := &periodic{ - period: seconds, - done: make(chan bool), - } - - periodics = append(periodics, ret) - - return ret -} - func Loop() { c := client.NewClientFromEnv() @@ -51,16 +38,17 @@ func Loop() { } } -func (p *periodic) InWorkspace(name string) *periodic { - if p.workspaceClientGetter != nil { - panic("Multiple calls to InWorkspace()") +func InWorkspace(name string) *periodic { + ret := &periodic{ + done: make(chan bool), + workspaceClientGetter: func(c *client.Client) (*client.WorkspaceClient, error) { + return c.InWorkspace(name) + }, } - p.workspaceClientGetter = func(c *client.Client) (*client.WorkspaceClient, error) { - return c.InWorkspace(name) - } + periodics = append(periodics, ret) - return p + return ret } // Query mutators