lib/app/ingest-services.go

65 lines
1.8 KiB
Go
Raw Permalink Normal View History

2021-02-06 21:18:47 +00:00
package app
import (
"fmt"
"time"
"code.tnxs.net/taxnexus/lib/api/devops/devops_client/ingest"
"code.tnxs.net/taxnexus/lib/api/devops/devops_models"
"github.com/google/uuid"
)
// NewIngestParams is a prams type
type NewIngestParams struct {
2021-02-06 22:33:20 +00:00
AccountID string
BackendID string
ObjectType string
ObjList []*devops_models.Ingest
Principal *User
Ref string
2021-02-06 21:18:47 +00:00
}
// NewIngest is an ingest helper function
func NewIngest(params *NewIngestParams) (string, error) {
sugar.Debug("ops.newIngest: 📥")
2021-02-06 22:33:20 +00:00
if params.AccountID == "" || params.Principal.TenantID == "" {
2021-02-06 21:18:47 +00:00
return "", fmt.Errorf("ops.newIngest: 💣 ⛔ params.AccountID or params.TaxnexusAccount are blank")
}
dt := time.Now().Format(dateTimeFormat)
theIngest := &devops_models.Ingest{
2021-02-06 22:33:20 +00:00
AccountID: &params.AccountID,
BackendID: params.BackendID,
2021-02-06 21:18:47 +00:00
EndDate: dt,
ID: uuid.New().String(),
IngestDate: dt,
IngestType: "fabric",
2021-02-06 22:33:20 +00:00
ObjectType: &params.ObjectType,
Ref: params.Ref,
2021-02-06 21:18:47 +00:00
StartDate: dt,
Status: "new",
}
2021-02-06 22:33:20 +00:00
params.ObjList = []*devops_models.Ingest{theIngest}
2021-02-06 21:18:47 +00:00
_, err := PostIngests(params)
if err != nil {
return "", err
}
sugar.Debugf("ops.newIngest: 👍 📤, Ingest ID=%s", theIngest.ID)
return theIngest.ID, nil
}
// PostIngests is an ingest helper function
func PostIngests(params *NewIngestParams) ([]*devops_models.Ingest, error) {
2021-02-06 22:33:20 +00:00
sugar.Debugf("ops.postIngests: 📥 len=%d", len(params.ObjList))
2021-02-06 21:18:47 +00:00
devopsParams := ingest.NewPostIngestsParams()
devopsParams.IngestRequest = &devops_models.IngestRequest{
2021-02-06 22:33:20 +00:00
Data: params.ObjList,
2021-02-06 21:18:47 +00:00
}
2021-02-06 22:33:20 +00:00
response, err := devopsClient.Ingest.PostIngests(devopsParams, params.Principal.Auth)
2021-02-06 21:18:47 +00:00
if err != nil {
sugar.Errorf("ops.postIngests: 💣 ⛔ post to devops error %w", err)
return nil, err
}
sugar.Debugf("ops.postIngests: 👍 📤 len(ingests)=%d", len(response.Payload.Data))
return response.Payload.Data, nil
}