export

package
v0.0.0-...-f6959c2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: AGPL-3.0 Imports: 22 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, dir string) (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

func NewPostgresCursor

func NewPostgresCursor(
	cursor pgx.Rows,
	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 TaskCreator

type TaskCreator interface {
	Create(ctx context.Context, t TaskParameters) (*Task, error)
	Get(ctx context.Context, id string) (*Task, error)
	SetFormatter(t string, f OutputFormatter)
	GetFormatter(t string) OutputFormatter
}

TaskCreator is used to create export task.

type TaskExecutor

type TaskExecutor interface {
	TaskCreator
	RegisterType(t string, fetch FetchData)
	ExecuteTask(ctx context.Context, id string) error
	ProcessAbandonedTasks(ctx context.Context)
	DeleteOldTasks(ctx context.Context)
}

func NewTaskExecutor

func NewTaskExecutor(
	client mongo.DbClient,
	jobPublisher workers.JobPublisher,
	timezoneConfigProvider config.TimezoneConfigProvider,
	dir string,
	logger zerolog.Logger,
) TaskExecutor

type TaskParameters

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

Source Files

  • csv.go
  • cursor.go
  • models.go
  • task_executor.go

Jump to

Keyboard shortcuts

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