Documentation ¶
Overview ¶
Package subimporter implements a bulk ZIP/CSV importer of subscribers. It implements a simple queue for buffering imports and committing records to DB along with ZIP and CSV handling utilities. It is meant to be used as a singleton as each Importer instance is stateful, where it keeps track of an import in progress. Only one import should happen on a single importer instance at a time.
Index ¶
Constants ¶
const ( StatusNone = "none" StatusImporting = "importing" StatusStopping = "stopping" StatusFinished = "finished" StatusFailed = "failed" ModeSubscribe = "subscribe" ModeBlocklist = "blocklist" )
Various import statuses.
Variables ¶
var ( // ErrIsImporting is thrown when an import request is made while an // import is already running. ErrIsImporting = errors.New("import is already running") )
Functions ¶
func ValidateFields ¶
ValidateFields validates incoming subscriber field values.
Types ¶
type Importer ¶
Importer represents the bulk CSV subscriber import system.
func (*Importer) NewSession ¶
NewSession returns an new instance of Session. It takes the name of the uploaded file, but doesn't do anything with it but retains it for stats.
type Options ¶
type Options struct { UpsertStmt *sql.Stmt BlocklistStmt *sql.Stmt UpdateListDateStmt *sql.Stmt NotifCB models.AdminNotifCallback }
Options represents inport options.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a single import session.
func (*Session) ExtractZIP ¶
ExtractZIP takes a ZIP file's path and extracts all .csv files in it to a temporary directory, and returns the name of the temp directory and the list of extracted .csv files.
func (*Session) LoadCSV ¶
LoadCSV loads a CSV file and validates and imports the subscriber entries in it.
type Status ¶
type Status struct { Name string `json:"name"` Total int `json:"total"` Imported int `json:"imported"` Status string `json:"status"` // contains filtered or unexported fields }
Status reporesents statistics from an ongoing import session.
type SubReq ¶
type SubReq struct { models.Subscriber Lists pq.Int64Array `json:"lists"` ListUUIDs pq.StringArray `json:"list_uuids"` }
SubReq is a wrapper over the Subscriber model.