Documentation ¶
Index ¶
- Constants
- Variables
- func Connect(connect string) error
- func CreateAuditLog(ip, user, action, message string) error
- func DeleteMOC(id int) error
- func RandomBatchName(seq int) string
- func ValidMOC(code string) bool
- type AuditLog
- type Batch
- type Issue
- func FindAvailableIssuesByWorkflowStep(ws schema.WorkflowStep) ([]*Issue, error)
- func FindInProcessIssues() ([]*Issue, error)
- func FindIssue(id int) (*Issue, error)
- func FindIssueByKey(key string) (*Issue, error)
- func FindIssueByLocation(location string) (*Issue, error)
- func FindIssuesByBatchID(batchID int) ([]*Issue, error)
- func FindIssuesByKey(key string) ([]*Issue, error)
- func FindIssuesInPageReview() ([]*Issue, error)
- func FindIssuesOnDesk(userID int) ([]*Issue, error)
- func FindIssuesReadyForBatching() ([]*Issue, error)
- func FindIssuesWithErrors() ([]*Issue, error)
- func NewIssue(moc, lccn, dt string, ed int) *Issue
- func (i *Issue) ApproveMetadata(reviewerID int)
- func (i *Issue) Claim(byUserID int)
- func (i *Issue) DateEdition() string
- func (i *Issue) Key() string
- func (i *Issue) RejectMetadata(reviewerID int, notes string)
- func (i *Issue) Save() error
- func (i *Issue) SaveOp(op *magicsql.Operation) error
- func (i *Issue) SchemaIssue() (*schema.Issue, error)
- func (i *Issue) Unclaim()
- type Job
- type JobLog
- type MOC
- type Title
- type TitleList
Constants ¶
const ( BatchStatusPending = "pending" // Not yet built or in the process of being built BatchStatusQCReady = "qc_ready" // Ready for ingest onto staging BatchStatusOnStaging = "on_staging" // On the staging server awaiting QC BatchStatusFailedQC = "failed_qc" // On staging, but QC failed it; it needs to be pulled and fixed BatchStatusPassedQC = "passed_qc" // On staging, passed QC; it needs to be pulled from staging and pushed live BatchStatusLive = "live" // Batch has gone live; batch and its issues need to be archived BatchStatusLiveDone = "live_done" // Batch has gone live; batch and its issues have been archived and are no longer on the filesystem )
These are all possible batch status values
const ( JobObjectTypeBatch = "batch" JobObjectTypeIssue = "issue" )
Object types for consistently inserting into the database
Variables ¶
var DB *magicsql.DB
DB is meant as a global accessor to a long-living database connection
var Debug bool
Debug should be set to true if operations should be logged to stderr
Functions ¶
func Connect ¶
Connect takes a connection string, opens the database, and stores both the source sql.DB and the wrapped magicsql.DB
func CreateAuditLog ¶
CreateAuditLog writes the given data to audit_logs
func RandomBatchName ¶
RandomBatchName generates a unique name for the given sequence. The names are guaranteed not to duplicate any of the component pieces until one component's values have all been used. The full names are guaranteed not to duplicate until the longest list has been used up, at which point all lists will be reshuffled.
Types ¶
type AuditLog ¶
type AuditLog struct { ID int `sql:",primary"` When time.Time "sql:\"`when`\"" IP string User string Action string Message string }
AuditLog represents the audit_logs table
type Batch ¶
type Batch struct { ID int `sql:",primary"` MARCOrgCode string Name string CreatedAt time.Time Status string Location string // contains filtered or unexported fields }
Batch contains metadata for generating a batch XML. Issues can be associated with a single batch, and a batch will typically have many issues assigned to it.
func CreateBatch ¶
CreateBatch creates a batch in the database, using its ID to generate a unique batch name, and associating the given list of issues. This is inefficient, but it gets the job done.
func (*Batch) AwardYear ¶
AwardYear uses the batch creation date to produce the "award year" - this is the most similar value we can produce
func (*Batch) FullName ¶
FullName returns the name of a batch as it is needed for chronam / ONI.
Note that currently we assume all generated batches will be _ver01, because we would usually generate a completely new batch if one were in such a state as to need to be pulled from production.
type Issue ¶
type Issue struct { ID int `sql:",primary"` // Metadata MARCOrgCode string LCCN string Date string DateAsLabeled string Volume string // Titles are tied to issues by LCCN, and all issues must have a title in the // database, so we load these when we load the issue data Title *Title `sql:"-"` // This field is a bit confusing, but it is the NDNP field for the issue // "number", which is actually a string since it can contain things like // "ISSUE XIX" Issue string Edition int EditionLabel string PageLabelsCSV string PageLabels []string `sql:"-"` BatchID int // Which batch (if any) is this issue a part of? Error string // If set, a metadata curator reported a problem Location string // Where is this issue on disk? MasterBackupLocation string // Where is the master backup located? (born-digital only) HumanName string // What is the issue's "human" name (for consistent folder naming)? IsFromScanner bool // Is the issue scanned in-house? (Born-digital == false) HasDerivatives bool // Does the issue have derivatives done? WorkflowStepString string `sql:"workflow_step"` // If set, tells us what "human workflow" step we're on WorkflowStep schema.WorkflowStep `sql:"-"` WorkflowOwnerID int // Whose "desk" is this currently on? WorkflowOwnerExpiresAt time.Time // When does the workflow owner lose ownership? MetadataEntryUserID int // Who entered metadata? ReviewedByUserID int // Who reviewed metadata? MetadataApprovedAt time.Time // When was metadata approved / how long has this been waiting to batch? RejectionNotes string // If rejected (during metadata review), this tells us why RejectedByUserID int // Who did the rejection? Ignored bool // Is the issue bad / in prod / otherwise skipped from workflow scans? }
Issue contains metadata about an issue for the various workflow tools' use
func FindAvailableIssuesByWorkflowStep ¶
func FindAvailableIssuesByWorkflowStep(ws schema.WorkflowStep) ([]*Issue, error)
FindAvailableIssuesByWorkflowStep looks for all "available" issues with the requested workflow step and returns them. We define "available" as:
- No owner (or owner expired) - Have not been reported as having errors
func FindInProcessIssues ¶
FindInProcessIssues returns all issues which have been entered in the workflow system, but haven't yet gone through all the way to the point of being batched and approved for production
func FindIssueByKey ¶
FindIssueByKey returns the first issue with the given key
func FindIssueByLocation ¶
FindIssueByLocation returns the first issue with the given location
func FindIssuesByBatchID ¶
FindIssuesByBatchID returns all issues associated with the given batch id
func FindIssuesByKey ¶
FindIssuesByKey looks for all issues in the database that have the given issue key. Having more than one is an error, but we allow users to save metadata in "draft" form, so we have to be able to test for dupes later in the process
func FindIssuesInPageReview ¶
FindIssuesInPageReview looks for all issues currently awaiting page review and returns them
func FindIssuesOnDesk ¶
FindIssuesOnDesk returns all issues "owned" by a given user id
func FindIssuesReadyForBatching ¶
FindIssuesReadyForBatching looks for all issues which are in the WSReadyForBatching workflow step and have no batch ID
func FindIssuesWithErrors ¶
FindIssuesWithErrors returns all issues with an error reported by metadata entry personnel
func (*Issue) ApproveMetadata ¶
ApproveMetadata moves the issue to the final workflow step (e.g., no more manual steps) and sets the reviewer id to that which was passed in
func (*Issue) Claim ¶
Claim sets the workflow owner to the given user id, and sets the expiration time to a week from now
func (*Issue) DateEdition ¶
DateEdition returns the date+edition string used by our general schema
func (*Issue) RejectMetadata ¶
RejectMetadata sends the issue back to the metadata entry user and saves the reviewer's notes
func (*Issue) SaveOp ¶
SaveOp creates or updates the Issue in the issues table with a custom operation
func (*Issue) SchemaIssue ¶
SchemaIssue returns an extremely over-simplified representation of this issue as a schema.Issue instance for ensuring consistent representation of things like issue keys
type Job ¶
type Job struct { ID int `sql:",primary"` CreatedAt time.Time `sql:",readonly"` StartedAt time.Time `sql:",noinsert"` CompletedAt time.Time `sql:",noinsert"` Type string `sql:"job_type"` ObjectID int ObjectType string Location string Status string // The job won't be run until sometime after RunAt; usually it's very close, // but the daemon doesn't pound the database every 5 milliseconds, so it can // take a little bit RunAt time.Time // Extra information any job might need - e.g., the issue's next workflow // step if the job is successful ExtraData string // QueueJobID tells us which job (if any) should be queued up after this one // completes successfully QueueJobID int // contains filtered or unexported fields }
A Job is anything the app needs to process and track in the background
func FindJobsByStatus ¶
FindJobsByStatus returns all jobs that have the given status
func FindJobsByStatusAndType ¶
FindJobsByStatusAndType returns all jobs of the given status and type
func FindJobsForIssueID ¶
FindJobsForIssueID returns all jobs tied to the given issue
func FindRecentJobsByType ¶
FindRecentJobsByType grabs all jobs of the given type which were created within the given duration or are still pending, for use in pulling lists of issues which are in the process of doing something
type JobLog ¶
type JobLog struct { ID int `sql:",primary"` JobID int CreatedAt time.Time `sql:",readonly"` LogLevel string Message string }
JobLog is a single log entry attached to a job
type MOC ¶
MOC contains MARC org codes
func FindMOCByCode ¶
FindMOCByCode searches the database for the given MOC and returns it if it's found, or nil if not
type Title ¶
type Title struct { ID int `sql:",primary"` Name string LCCN string Embargoed bool Rights string ValidLCCN bool SFTPDir string SFTPUser string SFTPPass string MARCTitle string MARCLocation string }
Title holds records from the titles table
func FindTitleByID ¶
FindTitleByID wraps FindTitle to simplify basic finding
func (*Title) SchemaTitle ¶
SchemaTitle converts a database Title to a schema.Title instance
type TitleList ¶
type TitleList []*Title
TitleList holds a full list of database titles for quick scan operations on all titles, such as is needed to do mass lookups of issues' LCCNs
func (TitleList) Find ¶
Find looks for the title by either directory name or LCCN to give a simpler way to find titles in a general case
func (TitleList) FindByDirectory ¶
FindByDirectory looks up a title by the given directory string, matching it against the sftp_dir field in the database
func (TitleList) FindByLCCN ¶
FindByLCCN returns the title matching the given LCCN or nil