Skip to content

Commit

Permalink
Fix: timeout and remove unused states
Browse files Browse the repository at this point in the history
  • Loading branch information
saimanoj committed Jul 29, 2023
1 parent ea78625 commit 40b2af4
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 54 deletions.
7 changes: 2 additions & 5 deletions client/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ func (s *Spec) Validate() error {

func (s *Spec) SetDefaults() {
if s.Timeout < 1 {
s.Timeout = 10
s.Timeout = 60
}
if s.MaxRetries < 1 {
s.MaxRetries = 30
}
if s.PageSize < 1 {
s.PageSize = 10
s.MaxRetries = 3
}
if s.Limit < 1 {
s.Limit = 100
Expand Down
2 changes: 0 additions & 2 deletions internal/ticketing/ticketing.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ func (s *Client) retryableRequest(ctx context.Context, integrationUrl string, pa
bodyStr = string(bdy)
}

log.Warn().Str("failed ", bodyStr).Err(err).Msg("Unknown Retry-After received")

if bodyStr == "" {
b, _ := json.Marshal(resp.Header)
bodyStr = "headers: " + string(b)
Expand Down
7 changes: 1 addition & 6 deletions resources/services/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func Collection() *schema.Table {
func fetchCollection(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
cl := meta.(*client.Client)

key := fmt.Sprintf("ticketing-collection-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId)
p := url.Values{}
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))
Expand Down Expand Up @@ -83,9 +82,5 @@ func fetchCollection(ctx context.Context, meta schema.ClientMeta, parent *schema
}
}

if err := cl.Backend.SetKey(ctx, key, time.Now().Format(time.RFC3339)); err != nil {
return fmt.Errorf("failed to store state to backend: %w", err)
}

return cl.Backend.Flush(ctx)
return nil
}
23 changes: 2 additions & 21 deletions resources/services/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,9 @@ func fetchComment(ctx context.Context, meta schema.ClientMeta, parent *schema.Re
if !ok {
return fmt.Errorf("parent.Item is not of type *ticketing.Collection, it is of type %T", parent.Item)
}
key := fmt.Sprintf("ticketing-comment-%s-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId, *ticket.Id)
p := url.Values{}

min, _ := time.Parse(time.RFC3339, cl.Spec.StartDate)
if cl.Backend != nil {
value, err := cl.Backend.GetKey(ctx, key)
p := url.Values{}

if err != nil {
return fmt.Errorf("failed to retrieve state from backend: %w", err)
}
if value != "" {
min, err = time.Parse(time.RFC3339, value)
if err != nil {
return fmt.Errorf("retrieved invalid state value: %q %w", value, err)
}
}
}
p.Set("since", min.Format(time.RFC3339))
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))

Expand All @@ -90,9 +75,5 @@ func fetchComment(ctx context.Context, meta schema.ClientMeta, parent *schema.Re
}
}

if err := cl.Backend.SetKey(ctx, key, time.Now().Format(time.RFC3339)); err != nil {
return fmt.Errorf("failed to store state to backend: %w", err)
}

return cl.Backend.Flush(ctx)
return nil
}
6 changes: 1 addition & 5 deletions resources/services/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func fetchTag(ctx context.Context, meta schema.ClientMeta, parent *schema.Resour
}
}
for _, collection := range collections {
key := fmt.Sprintf("ticketing-tag-%s-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId, *collection.Id)
p := url.Values{}
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))
Expand Down Expand Up @@ -100,10 +99,7 @@ func fetchTag(ctx context.Context, meta schema.ClientMeta, parent *schema.Resour
}
}

if err := cl.Backend.SetKey(ctx, key, time.Now().Format(time.RFC3339)); err != nil {
return fmt.Errorf("failed to store state to backend: %w", err)
}
}

return cl.Backend.Flush(ctx)
return nil
}
7 changes: 1 addition & 6 deletions resources/services/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func Team() *schema.Table {
func fetchTeam(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
cl := meta.(*client.Client)

key := fmt.Sprintf("ticketing-team-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId)
p := url.Values{}
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))
Expand Down Expand Up @@ -83,9 +82,5 @@ func fetchTeam(ctx context.Context, meta schema.ClientMeta, parent *schema.Resou
}
}

if err := cl.Backend.SetKey(ctx, key, time.Now().Format(time.RFC3339)); err != nil {
return fmt.Errorf("failed to store state to backend: %w", err)
}

return cl.Backend.Flush(ctx)
return nil
}
7 changes: 3 additions & 4 deletions resources/services/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func fetchTicket(ctx context.Context, meta schema.ClientMeta, parent *schema.Res
}

for _, collection := range collections {
fmt.Printf("Collection: %+v\n", collection)

key := fmt.Sprintf("ticketing-ticket-%s-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId, *collection.Id)
p := url.Values{}

Expand All @@ -95,14 +93,15 @@ func fetchTicket(ctx context.Context, meta schema.ClientMeta, parent *schema.Res
}
}
}
p.Set("since", min.Format(time.RFC3339))
p.Set("created_after", min.Format(time.RFC3339))
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))
cursor := fmt.Sprintf("%s/%s/tickets", cl.Spec.Url, *collection.Id)
for {
ret, p, err := cl.Services.GetTicket(ctx, cursor, p)
if err != nil {
return err
cl.Logger().Err(err)
return cl.Backend.Flush(ctx)
}
now := time.Now()
for i := range ret.Data {
Expand Down
6 changes: 1 addition & 5 deletions resources/services/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func fetchUser(ctx context.Context, meta schema.ClientMeta, parent *schema.Resou
}

for _, collection := range collections {
key := fmt.Sprintf("ticketing-user-%s-%s-%s", cl.Spec.WorkspaceId, cl.Spec.IntegrationAccountId, *collection.Id)
p := url.Values{}
p.Set("raw", "true")
p.Set("limit", strconv.FormatInt(cl.Spec.Limit, 10))
Expand Down Expand Up @@ -101,10 +100,7 @@ func fetchUser(ctx context.Context, meta schema.ClientMeta, parent *schema.Resou
}
}

if err := cl.Backend.SetKey(ctx, key, time.Now().Format(time.RFC3339)); err != nil {
return fmt.Errorf("failed to store state to backend: %w", err)
}
}

return cl.Backend.Flush(ctx)
return nil
}

0 comments on commit 40b2af4

Please sign in to comment.