job

package
Version: v0.0.0-...-dfcb032 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2014 License: MIT Imports: 23 Imported by: 6

Documentation

Overview

Document structs can either point to a url reference where the pdf is stored, or contain a blob of the data itself. The blob is compressed with zlib and then wrapped in Base64. These functions convert the encoded string to a []byte containing the pdf.

Package job provides the Job type and some methods on it. TODO caching s3 connection objects in a pool might speed things up. TODO use callback interface for different types of success notifications (e.g. command line and URL callbacks)

The downloaded docs list is generated in parallel, so it's not ordered correctly. These are functions to sort it in order of the original input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	Depth int
	Name  string
	Page  int
}

func (*Bookmark) String

func (b *Bookmark) String() string

type BookmarkList

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

func ExtractBookmarks

func ExtractBookmarks(cmd cpdf.InfoCmd) (bookmarks BookmarkList, err error)

func (BookmarkList) InCombinedContext

func (l BookmarkList) InCombinedContext(title string, offset int) (newBm BookmarkList)

InCombinedContext returns a new BookmarkList representing the document's bookmarks as they would appear in the context of a combined document. That is, a new level-0 bookmark is added with all existing bookmarks as children, and all pages are offset by the document's start position.

func (BookmarkList) String

func (l BookmarkList) String() string

type ByIndex

type ByIndex struct{ Documents }

func (ByIndex) Less

func (s ByIndex) Less(i, j int) bool

type Document

type Document struct {
	Key       string `json:"key"`
	Title     string `json:"title"`
	Data      string `json:"data,omitempty"`
	PageCount int    `json:"page_count"`
	FileSize  int    `json:"file_size"`

	Bookmarks BookmarkList `json:"-"`
	// contains filtered or unexported fields
}

A Document is a reference to one part of a combined PDF. it is is identified by its Key field, which is required. It can also have a Title, used for TOC bookmarks in the final combined document. The actual PDF data comes from one of two places:

- If the Data field is empty, the Key is treated as a S3 key that is
  fetched from the enclosing job's bucket.
- If the Data field is nonempty, it must contain a zlib-compressed
  and Base64-encoded string containing the PDF.

The bookmarks field is filled in by processing and is not serialized.

func (*Document) Get

func (doc *Document) Get() (docContent []byte, err error)

Get retrieves the requested document, either from S3 or by decoding the embedded `Data` attribute of the Document.

func (*Document) GetMetadata

func (doc *Document) GetMetadata(cmd cpdf.InfoCmd) (err error)

func (*Document) Id

func (doc *Document) Id() string

func (*Document) LocalPath

func (doc *Document) LocalPath() string

type Documents

type Documents []*Document

func (Documents) Len

func (docs Documents) Len() int

func (Documents) Swap

func (docs Documents) Swap(i, j int)

type Job

type Job struct {
	BucketName  string     `json:"bucket_name"`
	DocList     []Document `json:"doc_list"`
	Downloaded  Documents  `json:"downloaded"`
	CombinedKey string     `json:"combined_key"`
	Title       string     `json:"title,omitempty"`
	Callback    string     `json:"callback"`
	Errors      []error    `json:"errors"`

	DequeuedAt      time.Time
	DownloadsDoneAt time.Time
	// contains filtered or unexported fields
}

A Job includes all the data necessary to execute a pdf combination. It is mainly constructed from a JSON string in a HTTP request, but the last two fields contain internal state.

func New

func New(bucket string, docs []string) (newJob *Job, err error)

New is the default Job constructor.

func NewFromJSON

func NewFromJSON(encoded io.Reader) (newJob *Job, err error)

NewFromJSON constructs a Job from an io.Reader containing JSON conforming to the required portion of the Job schema.

func (*Job) AddError

func (j *Job) AddError(newErr error)

AddError adds to the list of encountered errors, translating obscure ones.

func (*Job) Cleanup

func (j *Job) Cleanup()

Delete the tmp directory for this job.

func (*Job) CleanupBrokenDocs

func (j *Job) CleanupBrokenDocs()

For every doc that failed for whatever reason, replace it with a page containing an error message.

func (*Job) CombinedBookmarkList

func (j *Job) CombinedBookmarkList() string

func (*Job) CombinedTitle

func (j *Job) CombinedTitle() string

Title returns the title of the document

func (*Job) CompleteCount

func (j *Job) CompleteCount() int

CompleteCount returns the number of documents actually completed.

func (*Job) ComponentPaths

func (j *Job) ComponentPaths() (paths []string)

Get the absolute paths to the completed docs.

func (*Job) Content

func (j *Job) Content() io.Reader

Content returns a Reader object that yields the job as JSON.

func (*Job) Dir

func (j *Job) Dir() string

func (*Job) DocCount

func (j *Job) DocCount() int

DocCount returns the number of documents requested.

func (*Job) DocsAreValid

func (j *Job) DocsAreValid() bool

func (*Job) HasDownloadedDocs

func (j *Job) HasDownloadedDocs() bool

HasDownloadedDocs determines whether any documents been successfully downloaded.

func (*Job) Id

func (j *Job) Id() string

func (*Job) IsSuccessful

func (j *Job) IsSuccessful() bool

In test mode, randomly fail 10% of the time.

func (*Job) IsValid

func (j *Job) IsValid() bool

IsValid determines whether the job contains all the fields necessary to start the combination.

func (*Job) LocalPath

func (j *Job) LocalPath() string

func (*Job) MarkComplete

func (j *Job) MarkComplete(doc *Document)

MarkComplete adds a document to the list of downloaded docs. TODO should be a Document.

func (*Job) Recipient

func (j *Job) Recipient() string

Recipient returns the notification URL to send status updates to.

func (*Job) SortDownloaded

func (j *Job) SortDownloaded()

SortDownloaded ensures that the Downloaded list is in the correct order.

func (*Job) ToJSON

func (j *Job) ToJSON() (jsonResponse []byte)

ToJSON serializes the Job into a JSON byte slice.

func (*Job) UploadCombinedFile

func (j *Job) UploadCombinedFile() (err error)

UploadCombinedFile sends a file to the job's CombinedKey on S3.

type JobResponse

type JobResponse struct {
	Success    bool        `json:"success"`
	Errors     []string    `json:"errors"`
	Downloaded []*Document `json:"downloaded"`
	Times      metrics     `json:"times"`
}

A JobResponse is sent as a notification -- it includes the success status as well as a subset of the job fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL