Documentation
¶
Overview ¶
Package queue holds the work queues: one file per session and one for the inbox, a line per item. Its functions return typed errors, so the command line and the dashboard can say the same thing in their own way.
Index ¶
- Constants
- Variables
- func Fits(items []textsafe.Text) int
- func Label(id state.ID) string
- func LabelFor(st state.Store, id state.ID) string
- func Missing(have []string, items []textsafe.Text) (add []textsafe.Text, skipped int)
- func MissingAt(have []string, items []textsafe.Text) (idx []int, skipped int)
- type Adoption
- type ChangedError
- type ConflictError
- type MergeResult
- type NoItemError
- type NotEndedError
- type Queue
- func (q Queue) Add(id state.ID, text textsafe.Text) (int, error)
- func (q Queue) Adopt(from, to state.ID, merge, dry bool, ended func(state.ID) bool, ...) (Adoption, error)
- func (q Queue) Count(id state.ID) int
- func (q Queue) Edit(id state.ID, n int, text textsafe.Text, guard *string) (textsafe.Text, error)
- func (q Queue) Merge(id state.ID, items []textsafe.Text) (MergeResult, error)
- func (q Queue) Move(from, to state.ID, n int, guard *string) (textsafe.Text, error)
- func (q Queue) Put(id state.ID, text textsafe.Text, same func(item string) bool) (replaced bool, n int, err error)
- func (q Queue) Remove(id state.ID, n int, guard *string) (textsafe.Text, error)
- func (q Queue) Reorder(id state.ID, from, to int, guard *string) (textsafe.Text, error)
- func (q Queue) Replace(id state.ID, items []textsafe.Text) (before, after int, err error)
- func (q Queue) Texts(id state.ID) []string
- type RangeError
Constants ¶
const MaxFileBytes = 4 << 20
MaxFileBytes is how large a queue file may grow by adding: the reader keeps 8 MiB, and a file past that would lose its end the next time it is rewritten.
const MaxItem = 4000
MaxItem is the longest item, in characters: long enough for a report that one session passes to another (docs/QUEUE-LENGTH.md). An item is one line; text with paragraphs is a Report.
const MaxTyped = 200
MaxTyped is the longest text a person types into a line, and the longest Objective: a + prompt, a line of the dashboard, a pin.
Variables ¶
var ErrBlank = errors.New("nothing to queue")
ErrBlank says the text to queue holds nothing.
var ErrEmpty = errors.New("queue empty")
ErrEmpty says the queue has no items.
var ErrFull = errors.New("queue full: remove some items first")
ErrFull says a queue file has reached MaxFileBytes.
var ErrNoSession = errors.New("no such session")
ErrNoSession says a bulk change was asked for a session that has no folder here. Merge and Replace never make one: a session exists because a hook saw it, and a restore must not invent one.
var ErrNothingToAdopt = errors.New("nothing to adopt")
ErrNothingToAdopt says the session has no items, no name, no pinned Objective and no parent, and its link to the adopting session, when one was asked for, is there already.
Functions ¶
func Fits ¶ added in v1.0.7
Fits is how many of the items Replace would write. A plan that says how many items a queue will hold uses the same count.
func Label ¶
Label is the short name of a queue: "inbox", or the first four characters of a session id.
func LabelFor ¶ added in v0.6.0
LabelFor is the name a person is shown for a queue: the session's alias when it has one, and Label otherwise.
func Missing ¶ added in v1.0.7
Missing says which of items a queue that holds have lacks, in the order given, and how many were there already. Items are compared by text with the rule of the JSON (trailing spaces do not count), and by number: when have holds "x" once and items holds it twice, one is missing. Blank items are in neither count. Merge adds exactly these, and a plan that shows what a merge would add uses the same function.
Types ¶
type Adoption ¶ added in v1.1.0
type Adoption struct {
Items []textsafe.Text // moved, in order
Name string // the name that went to the adopting session
NameKept string // the name left on the other session, because the adopting one has its own
Pin textsafe.Text // the pinned Objective that went to the adopting session
PinKept bool // a pinned Objective left on the other session, because the adopting one has its own
Parent state.ID // the parent of a Branch, whose link went to the adopting session, which had none
// ParentKept is the parent of a Branch whose link stayed on the other session, because the adopting one has its own or is above it
ParentKept state.ID
Linked bool // the record that the other session's conversation went on as the adopting one was written (docs/ADOPT-LINK.md)
Replaced state.ID // the session the other one's record named before
NotLinked string // why no record was written, when one was asked for and could not be
Before int // items the adopting session held before
}
Adoption is what Adopt moved, or with dry would move.
type ChangedError ¶
ChangedError says the queue is no longer what the caller saw.
func (*ChangedError) Error ¶
func (e *ChangedError) Error() string
type ConflictError ¶ added in v1.1.0
type ConflictError struct {
ID state.ID
Items int // items it holds, when both have items
Name string // its name, when both have a name
Pin bool // it has a pinned Objective, and so has the other
}
ConflictError says what the adopting session has already, in the places where the other session has something too. Merge keeps what it has.
func (*ConflictError) Error ¶ added in v1.1.0
func (e *ConflictError) Error() string
type MergeResult ¶ added in v1.0.7
type MergeResult struct {
Added int // appended to the queue
Skipped int // already in the queue, by text and by number
NotAdded int // left out because the queue file reached MaxFileBytes
}
MergeResult says what a merge did. Items that were blank are in none of the counts.
type NoItemError ¶
NoItemError says there is no item at that position.
func (*NoItemError) Error ¶
func (e *NoItemError) Error() string
type NotEndedError ¶ added in v1.1.0
NotEndedError says the session to adopt from has not ended.
func (*NotEndedError) Error ¶ added in v1.1.0
func (e *NotEndedError) Error() string
type Queue ¶
Queue is the set of queues in a state folder. Log records each change once it has succeeded; the zero Log is off.
func (Queue) Adopt ¶ added in v1.1.0
func (q Queue) Adopt(from, to state.ID, merge, dry bool, ended func(state.ID) bool, link func(from, to state.ID) (bool, string)) (Adoption, error)
Adopt gives the adopting session the other one's items, name and pinned Objective, in one hold of the lock. The items reach `to` before they leave `from`, so a failure can leave a duplicate but never lose one. Without merge, `to` must have nothing where `from` has something; with it, `to` keeps its own name and Objective, and the items go after its own. With dry, nothing is changed. A pinned Objective that is blank counts as none, on either session. ended, when set, is asked under the lock whether `from` has ended, so that a session resumed meanwhile is not adopted from. After an error the result lists only what did move. link, when set, asks for the record that from's conversation went on as to, written last; it is asked under the lock, and says whether to write it and, when it may not be written, why. A record that holds already is neither written nor something to adopt.
func (Queue) Edit ¶ added in v0.6.0
Edit replaces the text of item n and returns the text it had. The item keeps its place.
func (Queue) Merge ¶ added in v1.0.7
Merge adds the items that the queue lacks to its end, in the order given, and removes and reorders nothing. Items are compared by text with the rule of the JSON (trailing spaces do not count), and by number: when the queue holds "x" once and items holds it twice, one is added. It does the comparison and the appends in one hold of the lock, so that nothing added meanwhile is lost or counted twice, and it adds what fits under MaxFileBytes and says how many did not. The caller has cleaned and cut the items (MaxItem), and the change is not logged here: a bulk change is one entry, which the caller writes.
func (Queue) Move ¶
Move hands item n from one queue to the end of another and returns it. The item reaches the destination before it leaves the source, so a failure can leave a duplicate but never lose it.
func (Queue) Put ¶ added in v1.6.2
func (q Queue) Put(id state.ID, text textsafe.Text, same func(item string) bool) (replaced bool, n int, err error)
Put replaces the first item that same says is the same as text, or else appends text, in one hold of the lock, so that two runs at once leave one item. It says whether it replaced one, and returns how many items the queue holds. The queue's folder must be there: Put makes no session.
func (Queue) Replace ¶ added in v1.0.7
Replace makes the queue hold exactly these items, in this order, and says how many it held and how many it holds. Blank items are left out, and items past MaxFileBytes are not written (the count tells). The change is one write of the whole file under the lock. The caller has cleaned and cut the items, and the change is not logged here.
type RangeError ¶
RangeError says a position is past the end of the queue.
func (*RangeError) Error ¶
func (e *RangeError) Error() string