export

package
v0.0.0-...-8a398ea Latest Latest
Warning

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

Go to latest
Published: Dec 17, 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, fsg FieldsSeparatorGetter, 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 FieldsSeparatorGetter

type FieldsSeparatorGetter interface {
	GetFields() Fields
	GetSeparator() rune
}

type OutputFormatter

type OutputFormatter interface {
	GetFileExtension() string
	DataFetcher(context.Context, FieldsSeparatorGetter, DataCursor) (string, error)
}

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"`
}

func (Task) GetFields

func (t Task) GetFields() Fields

func (Task) GetSeparator

func (t Task) GetSeparator() rune

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)
	SetFormatter(t string, f OutputFormatter)
}

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