tasks

package
v0.0.0-...-95d4a42 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package tasks implements the core Pixur business logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthTokenFromCtx

func AuthTokenFromCtx(ctx context.Context) (token string, ok bool)

func CtxFromAuthToken

func CtxFromAuthToken(ctx context.Context, token string) context.Context

func CtxFromTestConfig

func CtxFromTestConfig(ctx context.Context, conf *schema.Configuration) context.Context

func CtxFromUserToken

func CtxFromUserToken(ctx context.Context, userId, tokenId int64) context.Context

func GetConfiguration

func GetConfiguration(ctx context.Context) (*schema.Configuration, status.S)

Types

type AddPicCommentTask

type AddPicCommentTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId           int64
	CommentParentId int64
	Text            string

	// Ext is additional extra data associated with this comment.
	Ext map[string]*any.Any

	// Outs
	UnfilteredPicComment *schema.PicComment
	PicComment           *schema.PicComment
}

func (*AddPicCommentTask) Run

func (t *AddPicCommentTask) Run(ctx context.Context) (stscap status.S)

type AddPicCommentVoteTask

type AddPicCommentVoteTask struct {
	Beg tab.JobBeginner
	Now func() time.Time

	PicId     int64
	CommentId int64

	Vote schema.PicCommentVote_Vote
	Ext  map[string]*anypb.Any

	// Result
	PicCommentVote *schema.PicCommentVote
}

func (*AddPicCommentVoteTask) Run

func (t *AddPicCommentVoteTask) Run(ctx context.Context) (stscap status.S)

type AddPicTagsTask

type AddPicTagsTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId    int64
	TagNames []string

	// Outputs
	TagNameToTagId map[string]int64 // all keys from TagNames are present, and no extras.
}

func (*AddPicTagsTask) Run

func (t *AddPicTagsTask) Run(ctx context.Context) (stscap status.S)

TODO: add tests

type AddPicVoteTask

type AddPicVoteTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId int64
	Vote  schema.PicVote_Vote
	// Ext is additional extra data associated with this vote.
	Ext map[string]*anypb.Any

	// Outs
	UnfilteredPicVote *schema.PicVote
	PicVote           *schema.PicVote
}

func (*AddPicVoteTask) Run

func (t *AddPicVoteTask) Run(ctx context.Context) (stscap status.S)

type AuthUserTask

type AuthUserTask struct {
	// Deps
	Beg                    tab.JobBeginner
	Now                    func() time.Time
	CompareHashAndPassword func(hashed, password []byte) error

	// Inputs
	Ident  string
	Secret string

	// Alt inputs
	UserId  int64
	TokenId int64

	// Results
	User       *schema.User
	NewTokenId int64
}

func (*AuthUserTask) Run

func (t *AuthUserTask) Run(ctx context.Context) (stscap status.S)

type CreateCustomDataTask

type CreateCustomDataTask struct {
	Beg tab.JobBeginner
	Now func() time.Time

	KeyType, Key1, Key2, Key3, Key4, Key5 int64
	Capability                            []schema.User_Capability

	Data *anypb.Any
}

func (*CreateCustomDataTask) Run

func (t *CreateCustomDataTask) Run(ctx context.Context) (stscap status.S)

type CreateUserTask

type CreateUserTask struct {
	// Deps
	Beg          tab.JobBeginner
	Now          func() time.Time
	HashPassword func([]byte) ([]byte, error)

	// Inputs
	Ident  string
	Secret string
	// Special input that overrides the defaults.  Used for site bootstrapping.
	Capability []schema.User_Capability

	// Ext is additional extra data associated with this user.
	Ext map[string]*any.Any

	// Results
	CreatedUser *schema.User
}

func (*CreateUserTask) Run

func (t *CreateUserTask) Run(ctx context.Context) (stscap status.S)

type FindCustomDataTask

type FindCustomDataTask struct {
	Beg tab.JobBeginner
	Now func() time.Time

	KeyType    int64
	KeyPrefix  []int64
	Capability []schema.User_Capability

	Data []*schema.CustomData
}

func (*FindCustomDataTask) Run

func (t *FindCustomDataTask) Run(ctx context.Context) (stscap status.S)

type FindPicCommentVotesTask

type FindPicCommentVotesTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId        int64
	CommentId    *int64
	ObjectUserId *int64

	// Results
	PicCommentVote []*schema.PicCommentVote
}

func (*FindPicCommentVotesTask) Run

func (t *FindPicCommentVotesTask) Run(ctx context.Context) (stscap status.S)

type FindSchedPicsTask

type FindSchedPicsTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	ObjectUserId int64

	// Outs
	UnfilteredPics []*schema.Pic
	Pics           []*schema.Pic
}

func (*FindSchedPicsTask) Run

func (t *FindSchedPicsTask) Run(ctx context.Context) (stscap status.S)

TODO: add tests

type FindSimilarPicsTask

type FindSimilarPicsTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId int64

	// Results
	SimilarPicIds []int64
}

func (*FindSimilarPicsTask) Run

func (t *FindSimilarPicsTask) Run(ctx context.Context) (stscap status.S)

type FindUserEventsTask

type FindUserEventsTask struct {
	Beg tab.JobBeginner
	Now func() time.Time

	// Input
	MaxUserEvents                           int64
	ObjectUserId                            int64
	StartUserId, StartCreatedTs, StartIndex int64
	Ascending                               bool

	// Output
	UserEvents                           []*schema.UserEvent
	NextUserId, NextCreatedTs, NextIndex int64
	PrevUserId, PrevCreatedTs, PrevIndex int64
}

func (*FindUserEventsTask) Run

func (t *FindUserEventsTask) Run(ctx context.Context) (stscap status.S)

type HardDeletePicTask

type HardDeletePicTask struct {
	// deps
	Beg     tab.JobBeginner
	PixPath string
	Remove  func(name string) error
	Now     func() time.Time

	// input
	PicId int64
}

func (*HardDeletePicTask) Run

func (t *HardDeletePicTask) Run(ctx context.Context) (stscap status.S)

type IncrementViewCountTask

type IncrementViewCountTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId int64
}

func (*IncrementViewCountTask) Run

func (t *IncrementViewCountTask) Run(ctx context.Context) (stscap status.S)

type LoadConfigurationTask

type LoadConfigurationTask struct {
	Beg db.Beginner

	// If non-nil, this will override any other configuration that might be used.
	Config *schema.Configuration
}

func (*LoadConfigurationTask) Run

func (t *LoadConfigurationTask) Run(ctx context.Context) (stscap status.S)

type LookupPicTask

type LookupPicTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId int64
	// If true, check if the user is allowed to read extended pic info.  The data will be included
	// regardless of if this is set, and the caller should remove the extended data.
	CheckReadPicExtCap bool
	// If true, check if the user is allowed to read extended comment info.  The data will be included
	// regardless of if this is set, and the caller should remove the extended data.
	CheckReadPicCommentExtCap bool
	// If true, check if the user is allowed to read extended pic tag info.  The data will be included
	// regardless of if this is set, and the caller should remove the extended data.
	CheckReadPicTagExtCap bool

	// Results
	UnfilteredPic  *schema.Pic
	Pic            *schema.Pic
	PicTags        []*schema.PicTag
	PicCommentTree *PicCommentTree
}

func (*LookupPicTask) Run

func (t *LookupPicTask) Run(ctx context.Context) (stscap status.S)

type LookupPicVoteTask

type LookupPicVoteTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	PicId        int64
	ObjectUserId int64

	// Results
	PicVote *schema.PicVote
}

func (*LookupPicVoteTask) Run

func (t *LookupPicVoteTask) Run(ctx context.Context) (stscap status.S)

type LookupUserTask

type LookupUserTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	ObjectUserId int64
	// If true, only public information about the user will be included.
	PublicOnly bool

	// Outs
	User *schema.User
}

func (*LookupUserTask) Run

func (t *LookupUserTask) Run(ctx context.Context) (stscap status.S)

type PicCommentTree

type PicCommentTree struct {
	PicComment *schema.PicComment
	Children   []*PicCommentTree
}

func (*PicCommentTree) String

func (pct *PicCommentTree) String() string

type PurgePicTask

type PurgePicTask struct {
	// deps
	PixPath string
	Beg     tab.JobBeginner
	Remove  func(name string) error
	Now     func() time.Time

	// input
	PicId int64
}

func (*PurgePicTask) Run

func (t *PurgePicTask) Run(ctx context.Context) (stscap status.S)

type ReadIndexPicsTask

type ReadIndexPicsTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	// Only get pics with Pic Id <= than this.  If unset, the latest pics will be returned.
	StartId int64
	// MaxPics is the maximum number of pics to return.  Note that the number of pictures returned
	// may be less than the number requested.  If unset, a default is used.
	MaxPics int64
	// Ascending determines the order of pics returned.
	Ascending bool

	// Results
	UnfilteredPics []*schema.Pic
	// Same as pics, but with User info removed based on capability
	Pics []*schema.Pic

	NextId, PrevId int64
}

func (*ReadIndexPicsTask) Run

func (t *ReadIndexPicsTask) Run(ctx context.Context) (stscap status.S)

type SoftDeletePicTask

type SoftDeletePicTask struct {
	// deps
	Beg tab.JobBeginner
	Now func() time.Time

	// input
	PicId int64
	// Represents when this Pic can be hard deleted.  Optional.
	PendingDeletionTime *time.Time

	// Why is this being deleted
	Reason  schema.Pic_DeletionStatus_Reason
	Details string

	// Can this picture ever be re uploaded?
	Temporary bool
}

func (*SoftDeletePicTask) Run

func (t *SoftDeletePicTask) Run(ctx context.Context) (stscap status.S)

type Task

type Task interface {
	Run(context.Context) status.S
}

type TaskRunner

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

func TestTaskRunner

func TestTaskRunner(run func(context.Context, Task) status.S) *TaskRunner

func (*TaskRunner) Run

func (r *TaskRunner) Run(ctx context.Context, task Task) status.S

type UnauthUserTask

type UnauthUserTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	UserId  int64
	TokenId int64
}

TODO: add tests

func (*UnauthUserTask) Run

func (t *UnauthUserTask) Run(ctx context.Context) (stscap status.S)

type UpdatePicTagTask

type UpdatePicTagTask struct {
	// deps
	Beg tab.JobBeginner
	Now func() time.Time

	// inputs
	PicId, TagId, Version int64

	Ext map[string]*anypb.Any
}

func (*UpdatePicTagTask) Run

func (t *UpdatePicTagTask) Run(ctx context.Context) (stscap status.S)

TODO: test

type UpdateUserTask

type UpdateUserTask struct {
	// Deps
	Beg tab.JobBeginner
	Now func() time.Time

	// Inputs
	ObjectUserId int64
	Version      int64

	// Capabilities to add
	SetCapability []schema.User_Capability
	// Capabilities to remove
	ClearCapability []schema.User_Capability

	// Outputs
	ObjectUser *schema.User
}

func (*UpdateUserTask) Run

func (t *UpdateUserTask) Run(ctx context.Context) (stscap status.S)

type UpsertPicTask

type UpsertPicTask struct {
	// Deps
	PixPath    string
	Beg        tab.JobBeginner
	HTTPClient *http.Client
	// os functions
	TempFile func(dir, prefix string) (*os.File, error)
	Rename   func(oldpath, newpath string) error
	MkdirAll func(path string, perm os.FileMode) error
	Now      func() time.Time
	Remove   func(name string) error

	// Inputs
	FileURL, FileURLReferrer string
	File                     readerAtReadSeeker
	Md5Hash                  []byte
	// If the name is absent, UpsertPicTask will try to derive a name automatically from the FileURL.
	FileName string

	// Ext is additional extra data associated with this pic.  If a key is present in both the
	// new pic and the existing pic, Upsert will fail.
	Ext map[string]*any.Any

	// Results
	UnfilteredCreatedPic *schema.Pic
	CreatedPic           *schema.Pic
}

UpsertPicTask inserts or updates a pic with the provided information.

func (*UpsertPicTask) Run

func (t *UpsertPicTask) Run(ctx context.Context) (stscap status.S)

type UserToken

type UserToken struct {
	UserId  int64
	TokenId int64
}

func UserTokenFromCtx

func UserTokenFromCtx(ctx context.Context) (tok *UserToken, ok bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL