job

package
v0.0.0-...-aadc1fd Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailRecordNotFound = errors.New("fail record not found")
	ErrJobNotExists       = errors.New("job not exists")
)

Functions

This section is empty.

Types

type CSVProcess

type CSVProcess struct {
	// contains filtered or unexported fields
}

func (CSVProcess) Process

func (c CSVProcess) Process(file *os.File) (ProcessResult, error)

type ColumnName

type ColumnName string
var (
	GithubID       ColumnName = "github_id"
	GithubUsername ColumnName = "github_username"
	DisplayName    ColumnName = "display_name"
	ProfileImage   ColumnName = "profile_image"
	Bio            ColumnName = "bio"
	PrivacyMode    ColumnName = "privacy_mode"
	Email          ColumnName = "email"
)

func (ColumnName) String

func (c ColumnName) String() string

type ConfigJob

type ConfigJob struct {
	StoragePath  string `koanf:"storage_path"`
	CsvFile      string `koanf:"csv_file"`
	XlsxFile     string `koanf:"xlsx_file"`
	ProcessCount int    `koanf:"process_count"`
	BufferSize   int    `koanf:"buffer_size"`
}

type ContributorAdapter

type ContributorAdapter struct {
	// contains filtered or unexported fields
}

func NewContributorAdapter

func NewContributorAdapter(contrSvc ContributorRepo) ContributorAdapter

func (ContributorAdapter) UpsertContributor

func (c ContributorAdapter) UpsertContributor(ctx context.Context, req ContributorRecord) error

type ContributorRecord

type ContributorRecord struct {
	RowNumber      int
	GithubID       int64
	GithubUsername string
	DisplayName    string
	ProfileImage   string
	Bio            string
	PrivacyMode    string
	Email          string
	CreatedAt      time.Time
}

type ContributorRepo

type ContributorRepo interface {
	Upsert(ctx context.Context, contributor contributor.UpsertContributorRequest) (contributor.UpsertContributorResponse, error)
}

type FailRecord

type FailRecord struct {
	ID           uint
	JobID        uint
	RecordNumber int
	Reason       string
	RawData      []string
	RetryCount   int
	LastError    string
	ErrType      RecordErrType
	CreatedAt    time.Time
	UpdatedAt    *time.Time
}

type FailRepository

type FailRepository interface {
	Create(ctx context.Context, failRecord FailRecord) error
	GetByJobID(ctx context.Context, jobID uint) ([]FailRecord, error)
}

type FileProcessor

type FileProcessor interface {
	Process(file *os.File) (ProcessResult, error)
}

type GetFailRecordsResponse

type GetFailRecordsResponse struct {
	ID           uint          `json:"id"`
	JobID        uint          `json:"job_id"`
	RecordNumber int           `json:"record_number"`
	Reason       string        `json:"reason"`
	RawData      []string      `json:"raw_data"`
	RetryCount   int           `json:"retry_count"`
	LastError    string        `json:"last_error"`
	ErrType      RecordErrType `json:"err_type"`
	CreatedAt    time.Time     `json:"created_at"`
	UpdatedAt    *time.Time    `json:"updated_at"`
}

type GetJobResponse

type GetJobResponse struct {
	ID             uint      `json:"ID"`
	TotalRecords   int       `json:"total_records,omitempty"`
	SuccessCount   int       `json:"success_count,omitempty"`
	FailCount      int       `json:"fail_count,omitempty"`
	IdempotencyKey string    `json:"idempotency_key"`
	FileHash       string    `json:"file_hash"`
	FileName       string    `json:"file_name"`
	FilePath       string    `json:"file_path"`
	Status         Status    `json:"status"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at,omitempty"`
}

type ImportContributorRequest

type ImportContributorRequest struct {
	File           multipart.File `json:"file"`
	FileName       string         `json:"file_name"`
	FileType       string         `json:"file_type"`
	IdempotencyKey string         `json:"idempotency_key"`
}

type ImportContributorResponse

type ImportContributorResponse struct {
	JobID   uint   `json:"job_id"`
	Message string `json:"message"`
}

type Job

type Job struct {
	ID             uint
	TotalRecords   int
	SuccessCount   int
	FailCount      int
	IdempotencyKey string
	FileHash       string
	FileName       string
	FilePath       string
	Status         Status
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type ProcessResult

type ProcessResult struct {
	Total          int
	Success        int
	Fail           int
	SuccessRecords []ContributorRecord
	FailRecords    []FailRecord
}

type ProduceJob

type ProduceJob struct {
	JobID          uint
	IdempotencyKey string
}

type Publisher

type Publisher interface {
	Publish(ctx context.Context, pj ProduceJob) error
}

type RecordErrType

type RecordErrType int
const (
	ErrTypeValidation RecordErrType = iota + 1
	ErrTypeUnexpected
)

type RecordProcessError

type RecordProcessError struct {
	Type RecordErrType
	Err  error
}

func (RecordProcessError) Error

func (e RecordProcessError) Error() string

type Repository

type Repository interface {
	CreateJob(ctx context.Context, job Job) (uint, error)
	GetJobByIdempotencyKey(ctx context.Context, key string) (*Job, error)
	GetJobByFileHash(ctx context.Context, fileHash string) (*Job, error)
	GetJobByID(ctx context.Context, ID uint) (Job, error)
	UpdateStatus(ctx context.Context, jobID uint, status Status) error
	UpdateJob(ctx context.Context, job Job) error
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(
	cfg ConfigJob,
	repo Repository,
	pub Publisher,
	contributorAdapter ContributorAdapter,
	failRecord FailRepository,
	validator ValidatorJobRepo) Service

func (Service) CreateImportJob

func (Service) GetFailRecords

func (s Service) GetFailRecords(ctx context.Context, jobID uint) ([]GetFailRecordsResponse, error)

func (Service) JobStatus

func (s Service) JobStatus(ctx context.Context, id uint) (GetJobResponse, error)

func (Service) ProcessJob

func (s Service) ProcessJob(ctx context.Context, jobID uint) error

type Status

type Status string
var (
	Pending        Status = "pending"
	PendingToQueue Status = "pending_to_queue"
	Success        Status = "success"
	Failed         Status = "failed"
	PartialSuccess Status = "partial_success"
	Processing     Status = "processing"
)

type ValidateConfig

type ValidateConfig struct {
	HttpFileType []string `koanf:"http_file_type"`
}

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func (Validator) ImportJobRequestValidate

func (v Validator) ImportJobRequestValidate(req ImportContributorRequest) error

type ValidatorJobRepo

type ValidatorJobRepo interface {
	ImportJobRequestValidate(req ImportContributorRequest) error
}

func NewValidator

func NewValidator(cfg ValidateConfig) ValidatorJobRepo

type XLSXProcess

type XLSXProcess struct {
	// contains filtered or unexported fields
}

func (XLSXProcess) Process

func (x XLSXProcess) Process(file *os.File) (ProcessResult, error)

Jump to

Keyboard shortcuts

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