export

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskStatusRunning = iota
	TaskStatusSucceeded
	TaskStatusFailed
)

Variables

This section is empty.

Functions

func ToCsv

func ToCsv(
	ctx context.Context,
	exportFields Fields,
	separator rune,
	dataCursor DataCursor,
) (resFileName string, resErr error)

ToCsv fetches data and saves it in csv file.

Types

type DataCursor

type DataCursor interface {
	Next(ctx context.Context) bool
	Scan(*map[string]any) error
	Close(ctx context.Context) error
}

func NewMongoCursor

func NewMongoCursor(
	cursor mongo.Cursor,
	fields []string,
	transform func(k string, v any) any,
) DataCursor

type FetchData

type FetchData func(ctx context.Context, t Task) (DataCursor, error)

type Field

type Field struct {
	Name     string `bson:"name" json:"name"`
	Label    string `bson:"label" json:"label"`
	Template string `bson:"template" json:"template"`
}

type Fields

type Fields []Field

func (*Fields) Fields

func (f *Fields) Fields() []string

func (*Fields) Labels

func (f *Fields) Labels() []string

type Task

type Task struct {
	ID         string            `bson:"_id"`
	Status     int64             `bson:"status"`
	Type       string            `bson:"type"`
	Parameters string            `bson:"parameters"`
	Fields     Fields            `bson:"fields"`
	Separator  rune              `bson:"separator"`
	File       string            `bson:"file,omitempty"`
	Filename   string            `bson:"filename"`
	FailReason string            `bson:"fail_reason,omitempty"`
	User       string            `bson:"user"`
	Created    datetime.CpsTime  `bson:"created"`
	Launched   *datetime.CpsTime `bson:"launched,omitempty"`
	Completed  *datetime.CpsTime `bson:"completed,omitempty"`
}

type TaskExecutor

type TaskExecutor interface {
	RegisterType(t string, fetch FetchData)
	// Execute receives tasks from channel and save its result to storage.
	Execute(ctx context.Context)
	// StartExecute creates new export task.
	StartExecute(ctx context.Context, t TaskParameters) (*Task, error)
	Get(ctx context.Context, id string) (*Task, error)
}

TaskExecutor is used to implement export task executor.

func NewTaskExecutor

func NewTaskExecutor(
	client mongo.DbClient,
	timezoneConfigProvider config.TimezoneConfigProvider,
	logger zerolog.Logger,
) TaskExecutor

type TaskParameters

type TaskParameters struct {
	Type           string
	Parameters     string
	Fields         Fields
	Separator      rune
	FilenamePrefix string
	UserID         string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL