Documentation
¶
Overview ¶
Package tasks is the tasks service: tasks derived from items, captured by the user or opened by other services, and the verbs that move them.
Index ¶
- Constants
- Variables
- func Once[T any](ctx context.Context, key string, load func() (T, error)) (T, error)
- func WithPass(ctx context.Context, p *Pass) context.Context
- type Authority
- type CardFacts
- type Deps
- type Facts
- type Gates
- type Items
- type OpenRequest
- type OwedBy
- type Page
- type Pass
- type ProjectDeps
- type ProjectDossiers
- type ProjectState
- type ProjectStore
- type PropStore
- type Reader
- type Recategorizer
- type Request
- type Result
- type Review
- type ReviewStep
- type Service
- func (s *Service) Accepts(t task.Task, v task.Verb, a task.Actor) error
- func (s *Service) Allowed(ctx context.Context, t task.Task, req Request) (gated bool, err error)
- func (s *Service) Attach(ctx context.Context, id task.ID, u unit.Unit) error
- func (s *Service) Capture(ctx context.Context, title, notes string, u *unit.Unit) (task.Task, error)
- func (s *Service) Children(ctx context.Context) (map[task.ID][]task.ID, error)
- func (s *Service) Close(ctx context.Context, id task.ID, to task.Category) error
- func (s *Service) Counts(ctx context.Context, area string) (task.Counters, error)
- func (s *Service) CountsWhere(ctx context.Context, area string, keep func(task.Task) (bool, error)) (task.Counters, error)
- func (s *Service) Do(ctx context.Context, id task.ID, req Request) (Result, error)
- func (s *Service) Handles(e task.Task, verb task.Verb) bool
- func (s *Service) Nudged(ctx context.Context, id task.ID, u unit.Unit, its []string, at time.Time) error
- func (s *Service) Open(ctx context.Context, r OpenRequest) (task.Task, error)
- func (s *Service) ProjectsStatus(ctx context.Context) (map[task.ID]ProjectState, error)
- func (s *Service) PropsOf(ctx context.Context, id task.ID) (task.Props, error)
- func (s *Service) Recategorize(ctx context.Context) ([]string, error)
- func (s *Service) RecordVerb(ctx context.Context, e task.Task, req Request) error
- func (s *Service) Register(class, handler string, h VerbHandler)
- func (s *Service) RegisterView(over, prefix string, src ViewSource)
- func (s *Service) ReopenOwn(ctx context.Context, u unit.Unit) (task.ID, bool, error)
- func (s *Service) Retitle(ctx context.Context, id task.ID, title string) error
- func (s *Service) Review(ctx context.Context) (Review, error)
- func (s *Service) ReviewStepDone(ctx context.Context, step string) (Review, error)
- func (s *Service) Rouse(ctx context.Context, id task.ID) error
- func (s *Service) ServeProjects(d ProjectDeps)
- func (s *Service) ServesReview() bool
- func (s *Service) SetMe(me task.Me)
- func (s *Service) SetProp(ctx context.Context, id task.ID, name string, v task.Value, w task.Writer) error
- func (s *Service) Sleep(ctx context.Context, id task.ID, w wake.Wake) error
- func (s *Service) Sync(ctx context.Context, units []unit.Unit) error
- func (s *Service) Task(ctx context.Context, id task.ID) (task.Task, error)
- func (s *Service) Tasks(ctx context.Context, q task.Query) ([]task.Task, error)
- func (s *Service) TasksOf(ctx context.Context, u unit.Unit) ([]task.Task, error)
- func (s *Service) TasksSince(ctx context.Context, q task.Query, since Since) (Page, error)
- func (s *Service) UnitClosed(ctx context.Context, u unit.Unit) error
- func (s *Service) WakeOf(ctx context.Context, id task.ID) (wake.Wake, bool, error)
- type Since
- type States
- type Store
- type VerbHandler
- type ViewEval
- type ViewSort
- type ViewSource
- type ViewSpec
- type Views
- type Wakes
Constants ¶
const ( // HandlerFinish and HandlerDrop are a move and nothing else, unless a kind registers its own handler of // them. HandlerFinish = "finish" HandlerDrop = "drop" )
The handlers the service runs itself as part of a verb's move; a verb with another handler moves nothing on its own: a registered handler or the daemon runs it.
const EveryKind = "*"
EveryKind registers a handler for the stored tasks no class-specific handler serves.
Variables ¶
var ( ErrNoTask = errors.New("no such task") ErrVerb = errors.New("the task's state refuses the verb") // ErrArgs is a request the service cannot read: an unknown verb or view, or a missing or bad argument. ErrArgs = errors.New("bad task request") // ErrPluginDisabled refuses a change to a task whose unit's plugin is disabled. ErrPluginDisabled = errors.New("the unit's plugin is disabled") // ErrForbidden refuses a verb its actor may not run on the task, as the profile's by says. ErrForbidden = errors.New("the actor may not run the verb") )
Functions ¶
Types ¶
type Authority ¶
type Authority func(ctx context.Context, verb string, a task.Actor, t task.Task) (allow, gate bool, err error)
Authority says whether actor a may run verb on task t (allow), and whether running it opens the verb's gate instead (gate).
type CardFacts ¶
type CardFacts struct {
Cards card.Store
// Enabled says whether a provider's plugin is enabled; nil: every one is.
Enabled func(unit.ProviderID) bool
// Me is the user's identity now; nil: nobody.
Me func() task.Me
// Kind is the value of the kind property a provider's plugin gives the tasks of its units; nil: none.
Kind func(unit.ProviderID) string
}
CardFacts reads a unit's facts from its stored card (#unit-card).
type Deps ¶
type Deps struct {
Store Store
Items Items
Facts Facts
Me task.Me
Clock port.Clock
// States are the profile's states and verbs; the service reads a task's category from its state.
States States
// Disabled are the providers whose plugin is disabled now; nil: none is.
Disabled func() []unit.ProviderID
// Authority says who may run each verb, as the profile's by does; nil, with no profile at hand: a person
// may run every verb and no other actor any.
Authority Authority
// Gates opens the gate a gated verb opens; nil: a gated verb fails.
Gates Gates
// Wakes are the tasks' wakes, which schedule puts and wake reads; nil: schedule fails and no task has one.
Wakes Wakes
// Baseline fills a wake Sleep puts on task t: a When that asks to wake once a fact of t changes becomes the
// condition over the value t has now; nil leaves every When as it is.
Baseline func(ctx context.Context, t task.Task, when string) (string, error)
// Views are the profile's views as it loads now; nil lists none.
Views func() Views
// ViewEval places a stored task in the profile's views; nil places none.
ViewEval ViewEval
// ViewSort orders a view's tasks as the profile sorts it; nil keeps their base order.
ViewSort ViewSort
// Activity is told each task Sync finds asleep with a person's activity on its unit since the user saw it,
// for a wake on activity; nil: none is told.
Activity func(ctx context.Context, id task.ID) error
}
Deps is what the service runs on.
type Gates ¶
type Gates interface {
Open(ctx context.Context, g gate.Gate) (gate.Gate, error)
Get(ctx context.Context, id int64) (gate.Gate, error)
OfTask(ctx context.Context, id task.ID) ([]gate.Gate, error)
}
Gates are the gates a gated verb opens and reads back: one open gate per proposal.
type OpenRequest ¶
type OwedBy ¶
OwedBy is who owes task t's next step, as tasks.toml's owed_by says: "me", a person's key, or "" when nobody does.
type Pass ¶
Pass is one evaluation of the views over the tasks: every task it ranges over, so a fact over a task's parent or children reads them here rather than in the store, and what an evaluator read of each task, kept for the pass.
type ProjectDeps ¶
type ProjectDeps struct {
Store ProjectStore
Dossiers ProjectDossiers // nil keeps no dossiers
}
type ProjectDossiers ¶
type ProjectDossiers interface {
Open(ctx context.Context, id task.ID) error
Resolved(ctx context.Context, id task.ID, at time.Time) error
}
ProjectDossiers opens a new project's dossier, its task's, and starts its lifecycle once the project ends (#dossier).
type ProjectState ¶
type ProjectState struct {
task.ProjectStatus
Due bool // past its review interval
}
ProjectState is a project's status at the service's now.
type ProjectStore ¶
type ProjectStore interface {
// CurrentRun is the Review run with a step still open.
CurrentRun(ctx context.Context) (task.ReviewRun, bool, error)
PutRun(ctx context.Context, r task.ReviewRun) error
}
ProjectStore keeps what the projects need beyond their tasks: the Review's runs.
type PropStore ¶
type PropStore interface {
SetProp(ctx context.Context, id task.ID, name string, v task.Value, w task.Writer) error
PropsOf(ctx context.Context, id task.ID) (task.Props, error)
}
PropStore keeps the tasks' properties. SetProp replaces the property's value and records its writer; a zero Value deletes the property, which PropsOf then leaves out. ErrNoTask when the task does not exist. It checks no type and no writer: the caller holds the profile that declares them. PropsOf are a task's properties, empty for one with none.
type Reader ¶
type Reader interface {
Tasks(ctx context.Context, q task.Query) ([]task.Task, error)
// TasksSince is the page after position since: Full, with q's tasks, when since is from another epoch or
// ahead of the store; else the tasks written after since's Rev, whatever their category. Removed is empty
// and Counters zero: the service fills them.
TasksSince(ctx context.Context, q task.Query, since Since) (Page, error)
Task(ctx context.Context, id task.ID) (task.Task, error) // ErrNoTask; ErrVerb is a verb the task's state refuses, naming both
TasksOf(ctx context.Context, u unit.Unit) ([]task.Task, error)
}
Reader is the read half of Store. Its lists read q.All only: every task, or the open ones; the views over them are the service's.
type Recategorizer ¶
type Recategorizer interface {
Recategorize(ctx context.Context, of func(state string) (task.Category, bool)) (unknown []string, err error)
}
Recategorizer rewrites the stored tasks' categories from their states, as of reads them, noting the tasks it moved. Unknown are the states tasks hold that of does not know; their tasks keep their category.
type Request ¶
type Request struct {
Verb task.Verb
Args map[string]string
Source string
Actor task.Actor
Chain workflow.Chain
Approved int64
}
Request is a verb to run. Actor is who runs it, required; Source where it came from (the cockpit, a workflow's name). Chain is the chain of workflows that led to it, which its event carries on. Approved is the approved gate a gated run of the verb opened, which ProposedVerb sets and no route copies: the person's approval stands for the verb's by.
type Review ¶
type Review struct {
ID string
StartedAt time.Time
Steps []ReviewStep
Done bool
}
Review is the review as it stands: its steps in order, each with its count. ID is empty while nothing was left to review when it started, so nothing was recorded.
type ReviewStep ¶
ReviewStep is a step of the review: the view it walks, how many it lists, and whether it is done.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) Accepts ¶
Accepts says whether actor a may run verb v on t as its move: ErrArgs for a verb the profile does not declare, ErrVerb naming the verb and the state for one t's state refuses or one whose handler the service does not run, ErrForbidden for one the profile's by does not let a run. A verb whose by opens a gate for a is accepted: running it opens the gate.
func (*Service) Allowed ¶
Allowed says whether req's actor may run req's verb on t, and whether running it opens the verb's gate instead, as the profile's authority says: ErrForbidden for a request with no actor or one the verb's by leaves out. A request an approved gate of t proposed (ProposedVerb) is allowed without the by.
func (*Service) Attach ¶
Attach adds u to task id's units, after those it holds; a unit it holds already changes nothing.
func (*Service) Capture ¶
func (s *Service) Capture(ctx context.Context, title, notes string, u *unit.Unit) (task.Task, error)
Capture files a new task in the Inbox.
func (*Service) Children ¶
Children are the open children of every parent, in sibling order: by Position, then id.
func (*Service) Close ¶
Close moves a task opened by Open or Capture into the done or the dropped category; a derived task, or one whose unit's plugin is disabled, refuses it.
func (*Service) CountsWhere ¶
func (s *Service) CountsWhere(ctx context.Context, area string, keep func(task.Task) (bool, error)) (task.Counters, error)
CountsWhere is Counts over the tasks keep holds, every task when nil: each view, area and context counts only the tasks of its list that keep takes, so a client's filter narrows the counters as it narrows the lists.
func (*Service) Do ¶
Do runs req.Verb on task id: a registered handler first, else the state change. A task of a unit whose plugin is disabled refuses every verb with ErrPluginDisabled but one whose handler is drop, which moves a derived task, or one whose units are all of disabled plugins, to the Trash whole, and detaches a disabled plugin's units from any other.
func (*Service) Nudged ¶
func (s *Service) Nudged(ctx context.Context, id task.ID, u unit.Unit, its []string, at time.Time) error
Nudged records a nudge sent at at on u about the items its draft listed: it writes the last_nudge property on the task id names and on every open task that holds one of the items on u, as the workflow that nudged. It reads them under the service's lock, so it never writes back a copy older than a concurrent Sync's, and it never moves last_nudge back.
func (*Service) Open ¶
Open creates a task another service owns the content of, such as a gate's: Inbox, random id. A task on a unit takes the kind its plugin gives its units' tasks (UnitFacts.Kind), as the plugin writes it, so the profile's rules for that kind apply to it; any other's kind is left to the profile.
func (*Service) ProjectsStatus ¶
ProjectsStatus is each live project's next action, open actions and review mark, over one read of the open set.
func (*Service) Recategorize ¶
Recategorize gives every stored task the category of its state as the profile declares it now, and returns the states stored tasks hold that the profile does not declare; those tasks keep their category. A store that keeps no categories recategorizes nothing.
func (*Service) RecordVerb ¶
RecordVerb records that req's actor ran req's verb on e, once the handler or the service that runs it succeeded.
func (*Service) Register ¶
func (s *Service) Register(class, handler string, h VerbHandler)
Register makes h run, before any state change, on the tasks of class the verbs whose profile handler is handler. A class is a value of the kind property, the origin task.OriginDraft or task.OriginMessage of a task another service serves, or EveryKind.
func (*Service) RegisterView ¶
func (s *Service) RegisterView(over, prefix string, src ViewSource)
RegisterView serves the views over over from src; task ids starting with prefix are read from it.
func (*Service) ReopenOwn ¶
ReopenOwn is u's own task when u's items key on u (task.UnitTask), moved back into the ready category, Changed, when it is done; ok is false when u's items key on no unit task or no task holds it. A dropped task stays dropped.
func (*Service) Retitle ¶
Retitle renames a task opened by Open or Capture, as one change; a derived task refuses it.
func (*Service) Review ¶
Review is the current review, or a new one: a step whose count is 0 at its start starts done, and a new review is recorded once a step is left to do.
func (*Service) ReviewStepDone ¶
ReviewStepDone marks step, the view it walks, done in the current review, recording the review once every step is.
func (*Service) Rouse ¶
Rouse drops task id's wake and returns the task where the wake said, as the wake verb does; a task with no wake is left as it is.
func (*Service) ServeProjects ¶
func (s *Service) ServeProjects(d ProjectDeps)
ServeProjects runs the project verbs on s (project with its position, sequential, reviewed), resolves an ending project's dossier, and serves the review.
func (*Service) ServesReview ¶
ServesReview says whether the review is served: ServeProjects gave it a store for its runs.
func (*Service) SetProp ¶
func (s *Service) SetProp(ctx context.Context, id task.ID, name string, v task.Value, w task.Writer) error
SetProp sets task id's property name to v as w wrote it, under the lock every other write of the service takes, so no write built from an older copy of the task undoes it; a zero v unsets it. It checks no type and no writer: the caller holds the profile that declares them.
func (*Service) Sleep ¶
Sleep defers open task id under w: a task not deferred moves to the first deferred state, and w returns it where it was; one deferred already keeps where its wake returned it, else its state. It is how a plugin's wake, such as a mute, holds a task.
func (*Service) Sync ¶
Sync reconciles the units named by a TopicItems, TopicSourceEvents or TopicCards note, in one Apply, then tells Activity the asleep tasks of those units a person's activity reached. A unit whose plugin is disabled keeps its tasks as they are.
func (*Service) Tasks ¶
Tasks is q's view: its tasks in the view's order, narrowed to q's area and contexts.
func (*Service) TasksSince ¶
TasksSince is q's page after since with the counters of q's area. A paged view's page from the same epoch lists the tasks written after since that are in the view, and removes those written that are not; any other view's page is Full, at the store's position.
func (*Service) UnitClosed ¶
UnitClosed ends the open tasks that hold u, its closure posted: each moves into the done category.
type States ¶
type States interface {
task.Profile
// Move is the states verb moves a task from (every state when empty) and the state it moves it to ("" for
// none); false when the profile declares no such verb.
Move(verb string) (from []string, to string, ok bool)
// Handler is the handler verb runs besides its move, "" for none.
Handler(verb string) string
// Gate is the gate a by.<actor> of "gate" on verb opens, as the profile declares it: its Name, Kind and
// Intents; false when the verb names none.
Gate(verb string) (gate.Gate, bool)
}
States are the profile's states (tasks.toml), the properties its roles act on and the transitions of its verbs.
type VerbHandler ¶
VerbHandler runs a verb another service owns (answer/approve/dismiss on messages, approve/dismiss on drafts); one on a stored task records the verb with Service.RecordVerb once it succeeded.
type ViewEval ¶
ViewEval says whether task t is in the profile's view; the service calls it inside a Pass, which ctx carries.
type ViewSort ¶
ViewSort orders a view's tasks in place as the profile sorts the view; they come in their base order: the oldest first, a parent's children in their sibling order.
type ViewSource ¶
type ViewSource interface {
Tasks(ctx context.Context, q task.Query) ([]task.Task, error)
Task(ctx context.Context, id task.ID) (task.Task, bool, error)
}
ViewSource serves the views over another thing than the stored tasks, such as the gates: Tasks are view q.View's, each what the view lists stands for, and Task reads a task of its own, whose id carries the prefix it is registered with; false for none.
type ViewSpec ¶
ViewSpec is a view of the profile as the service lists it. Over is what it lists: task.OverTasks, the stored tasks ViewEval places in it, or another, which the ViewSource registered for it serves. Paged says its predicate reads only what a write of the task itself moves, and not the time, so a page since a position lists only the tasks written after it; any other view is served Full. HideDisabled leaves out the tasks whose units are all of a disabled plugin.
type Views ¶
Views are the profile's views that list something, in its order, and the views its badge and its review name.
type Wakes ¶
type Wakes interface {
Put(ctx context.Context, w wake.Wake) error
Drop(ctx context.Context, id task.ID) error
Of(ctx context.Context, id task.ID) (wake.Wake, bool, error)
}
Wakes keeps the tasks' wakes, one per task: Put replaces a task's, Drop removes it, dropping none is no error, and Of is false for a task with none.