Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use a minimal airtable record in case the whole one generates a… #104

Merged
merged 1 commit into from
Oct 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ func airtableSync(opts *airtableOptions) error {
continue
}
logger().Debug("creating airtable record without slices", zap.String("URL", issue.URL))
r := issue.ToAirtableRecord()
r.Fields = airtableIssue{
URL: r.Fields.URL,
r := minimalAirtableRecord{
Fields: minimalAirtableIssue{
URL: issue.URL,
Errors: "initialization",
},
}
if err := table.Create(&r); err != nil {
return err
}
records = append(records, r)
records = append(records, airtableRecord{
ID: r.ID,
Fields: airtableIssue{
URL: issue.URL,
},
})
}

// update/destroy existing ones
Expand All @@ -125,8 +132,11 @@ func airtableSync(opts *airtableOptions) error {
record.Fields = issue.ToAirtableRecord().Fields
if err := table.Update(&record); err != nil {
logger().Warn("failed to update record, retrying without slices", zap.String("URL", issue.URL), zap.Error(err))
record.Fields = airtableIssue{
URL: record.Fields.URL,
record := minimalAirtableRecord{
ID: record.ID,
Fields: minimalAirtableIssue{
URL: issue.URL,
},
}
if typedErr, ok := err.(airtable.ErrClientRequest); ok {
record.Fields.Errors = typedErr.Err.Error()
Expand All @@ -148,6 +158,11 @@ type airtableRecord struct {
Fields airtableIssue `json:"fields,omitempty"`
}

type minimalAirtableRecord struct {
ID string `json:"id,omitempty"`
Fields minimalAirtableIssue `json:"fields,omitempty"`
}

func (ai airtableIssue) String() string {
out, _ := json.Marshal(ai)
return string(out)
Expand Down Expand Up @@ -201,6 +216,11 @@ type airtableIssue struct {
Errors string
}

type minimalAirtableIssue struct {
URL string
Errors string
}

func (ai airtableIssue) Equals(other airtableIssue) bool {
sameSlice := func(a, b []string) bool {
if a == nil {
Expand Down