mqueue

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2018 License: MIT Imports: 13 Imported by: 0

README

Simple message queue based on postgres, this is for more realiably sending messages with retry on failure, accepting long failture durations such as discord being down.

Documentation

Overview

IMPORTANT! This is auto generated code by https://github.com/src-d/go-kallax Please, do not touch the code below, and if you do, do it under your own risk. Take into account that all the code you write here will be completely erased from earth the next time you generate the kallax models.

Index

Constants

This section is empty.

Variables

View Source
var Schema = &schema{
	QueuedElement: &schemaQueuedElement{
		BaseSchema: kallax.NewBaseSchema(
			"mqueue",
			"__queuedelement",
			kallax.NewSchemaField("id"),
			kallax.ForeignKeys{},
			func() kallax.Record {
				return new(QueuedElement)
			},
			true,
			kallax.NewSchemaField("id"),
			kallax.NewSchemaField("source"),
			kallax.NewSchemaField("source_id"),
			kallax.NewSchemaField("message_str"),
			kallax.NewSchemaField("message_embed"),
			kallax.NewSchemaField("channel"),
			kallax.NewSchemaField("processed"),
		),
		ID:           kallax.NewSchemaField("id"),
		Source:       kallax.NewSchemaField("source"),
		SourceID:     kallax.NewSchemaField("source_id"),
		MessageStr:   kallax.NewSchemaField("message_str"),
		MessageEmbed: kallax.NewSchemaField("message_embed"),
		Channel:      kallax.NewSchemaField("channel"),
		Processed:    kallax.NewSchemaField("processed"),
	},
}

Functions

func IncrIDCounter added in v1.4.7

func IncrIDCounter() (next int64)

func InitStores

func InitStores()

func QueueMessage added in v1.4.7

func QueueMessage(source, sourceID string, channel int64, msgStr string, embed *discordgo.MessageEmbed)

func QueueMessageEmbed

func QueueMessageEmbed(source, sourceID string, channel int64, embed *discordgo.MessageEmbed)

func QueueMessageString

func QueueMessageString(source, sourceID string, channel int64, message string)

func RegisterPlugin added in v1.4.1

func RegisterPlugin()

func RegisterSource

func RegisterSource(name string, source PluginWithErrorHandler)

Types

type Plugin added in v1.4.1

type Plugin struct {
}

func (*Plugin) BotInit added in v1.4.1

func (p *Plugin) BotInit()

func (*Plugin) Name added in v1.4.1

func (p *Plugin) Name() string

func (*Plugin) StopBot added in v1.4.1

func (p *Plugin) StopBot(wg *sync.WaitGroup)

type PluginWithErrorHandler

type PluginWithErrorHandler interface {
	HandleMQueueError(elem *QueuedElementNoKallax, err error)
}

type QueuedElement

type QueuedElement struct {
	kallax.Model `table:"mqueue" pk:"id,autoincr"`

	ID int64

	// Where this feed originated from, responsible for handling discord specific errors
	Source string
	// Could be stuff like reddit feed element id, youtube feed element id and so on
	SourceID string

	// The actual message as a simple string
	MessageStr string

	// The actual message as an embed
	MessageEmbed string

	// The channel to send the message in
	Channel string

	Processed bool
}

func NewQueuedElement

func NewQueuedElement() (record *QueuedElement)

NewQueuedElement returns a new instance of QueuedElement.

func (*QueuedElement) ColumnAddress

func (r *QueuedElement) ColumnAddress(col string) (interface{}, error)

ColumnAddress returns the pointer to the value of the given column.

func (*QueuedElement) GetID

func (r *QueuedElement) GetID() kallax.Identifier

GetID returns the primary key of the model.

func (*QueuedElement) NewRelationshipRecord

func (r *QueuedElement) NewRelationshipRecord(field string) (kallax.Record, error)

NewRelationshipRecord returns a new record for the relatiobship in the given field.

func (*QueuedElement) SetRelationship

func (r *QueuedElement) SetRelationship(field string, rel interface{}) error

SetRelationship sets the given relationship in the given field.

func (*QueuedElement) Value

func (r *QueuedElement) Value(col string) (interface{}, error)

Value returns the value of the given column.

type QueuedElementNoKallax added in v1.4.7

type QueuedElementNoKallax struct {
	ID int64

	// Where this feed originated from, responsible for handling discord specific errors
	Source string
	// Could be stuff like reddit feed element id, youtube feed element id and so on
	SourceID string

	// The actual message as a simple string
	MessageStr string `json:",omitempty"`

	// The actual message as an embed
	MessageEmbed *discordgo.MessageEmbed `json:",omitempty"`

	// The channel to send the message in
	Channel int64
}

func NewElemFromKallax added in v1.4.7

func NewElemFromKallax(existing *QueuedElement) *QueuedElementNoKallax

type QueuedElementQuery

type QueuedElementQuery struct {
	*kallax.BaseQuery
}

QueuedElementQuery is the object used to create queries for the QueuedElement entity.

func NewQueuedElementQuery

func NewQueuedElementQuery() *QueuedElementQuery

NewQueuedElementQuery returns a new instance of QueuedElementQuery.

func (*QueuedElementQuery) BatchSize

func (q *QueuedElementQuery) BatchSize(size uint64) *QueuedElementQuery

BatchSize sets the number of items to fetch per batch when there are 1:N relationships selected in the query.

func (*QueuedElementQuery) Copy

Copy returns a new identical copy of the query. Remember queries are mutable so make a copy any time you need to reuse them.

func (*QueuedElementQuery) FindByChannel

func (q *QueuedElementQuery) FindByChannel(v string) *QueuedElementQuery

FindByChannel adds a new filter to the query that will require that the Channel property is equal to the passed value.

func (*QueuedElementQuery) FindByID

func (q *QueuedElementQuery) FindByID(v ...int64) *QueuedElementQuery

FindByID adds a new filter to the query that will require that the ID property is equal to one of the passed values; if no passed values, it will do nothing.

func (*QueuedElementQuery) FindByMessageEmbed

func (q *QueuedElementQuery) FindByMessageEmbed(v string) *QueuedElementQuery

FindByMessageEmbed adds a new filter to the query that will require that the MessageEmbed property is equal to the passed value.

func (*QueuedElementQuery) FindByMessageStr

func (q *QueuedElementQuery) FindByMessageStr(v string) *QueuedElementQuery

FindByMessageStr adds a new filter to the query that will require that the MessageStr property is equal to the passed value.

func (*QueuedElementQuery) FindByProcessed

func (q *QueuedElementQuery) FindByProcessed(v bool) *QueuedElementQuery

FindByProcessed adds a new filter to the query that will require that the Processed property is equal to the passed value.

func (*QueuedElementQuery) FindBySource

func (q *QueuedElementQuery) FindBySource(v string) *QueuedElementQuery

FindBySource adds a new filter to the query that will require that the Source property is equal to the passed value.

func (*QueuedElementQuery) FindBySourceID

func (q *QueuedElementQuery) FindBySourceID(v string) *QueuedElementQuery

FindBySourceID adds a new filter to the query that will require that the SourceID property is equal to the passed value.

func (*QueuedElementQuery) Limit

Limit sets the max number of items to retrieve.

func (*QueuedElementQuery) Offset

Offset sets the number of items to skip from the result set of items.

func (*QueuedElementQuery) Order

func (q *QueuedElementQuery) Order(cols ...kallax.ColumnOrder) *QueuedElementQuery

Order adds order clauses to the query for the given columns.

func (*QueuedElementQuery) Select

func (q *QueuedElementQuery) Select(columns ...kallax.SchemaField) *QueuedElementQuery

Select adds columns to select in the query.

func (*QueuedElementQuery) SelectNot

func (q *QueuedElementQuery) SelectNot(columns ...kallax.SchemaField) *QueuedElementQuery

SelectNot excludes columns from being selected in the query.

func (*QueuedElementQuery) Where

func (q *QueuedElementQuery) Where(cond kallax.Condition) *QueuedElementQuery

Where adds a condition to the query. All conditions added are concatenated using a logical AND.

type QueuedElementResultSet

type QueuedElementResultSet struct {
	ResultSet kallax.ResultSet
	// contains filtered or unexported fields
}

QueuedElementResultSet is the set of results returned by a query to the database.

func NewQueuedElementResultSet

func NewQueuedElementResultSet(rs kallax.ResultSet) *QueuedElementResultSet

NewQueuedElementResultSet creates a new result set for rows of the type QueuedElement.

func (*QueuedElementResultSet) All

func (rs *QueuedElementResultSet) All() ([]*QueuedElement, error)

All returns all records on the result set and closes the result set.

func (*QueuedElementResultSet) Close

func (rs *QueuedElementResultSet) Close() error

Close closes the result set.

func (*QueuedElementResultSet) Err

func (rs *QueuedElementResultSet) Err() error

Err returns the last error occurred.

func (*QueuedElementResultSet) ForEach

func (rs *QueuedElementResultSet) ForEach(fn func(*QueuedElement) error) error

ForEach iterates over the complete result set passing every record found to the given callback. It is possible to stop the iteration by returning `kallax.ErrStop` in the callback. Result set is always closed at the end.

func (*QueuedElementResultSet) Get

Get retrieves the last fetched item from the result set and the last error.

func (*QueuedElementResultSet) Next

func (rs *QueuedElementResultSet) Next() bool

Next fetches the next item in the result set and returns true if there is a next item. The result set is closed automatically when there are no more items.

func (*QueuedElementResultSet) One

One returns the first record on the result set and closes the result set.

type QueuedElementStore

type QueuedElementStore struct {
	*kallax.Store
}

QueuedElementStore is the entity to access the records of the type QueuedElement in the database.

func NewQueuedElementStore

func NewQueuedElementStore(db *sql.DB) *QueuedElementStore

NewQueuedElementStore creates a new instance of QueuedElementStore using a SQL database.

func (*QueuedElementStore) Count

Count returns the number of rows that would be retrieved with the given query.

func (*QueuedElementStore) Debug

Debug returns a new store that will print all SQL statements to stdout using the log.Printf function.

func (*QueuedElementStore) DebugWith

func (s *QueuedElementStore) DebugWith(logger kallax.LoggerFunc) *QueuedElementStore

DebugWith returns a new store that will print all SQL statements using the given logger function.

func (*QueuedElementStore) Delete

func (s *QueuedElementStore) Delete(record *QueuedElement) error

Delete removes the given record from the database.

func (*QueuedElementStore) Find

Find returns the set of results for the given query.

func (*QueuedElementStore) FindAll

FindAll returns a list of all the rows returned by the given query.

func (*QueuedElementStore) FindOne

FindOne returns the first row returned by the given query. `ErrNotFound` is returned if there are no results.

func (*QueuedElementStore) GenericStore

func (s *QueuedElementStore) GenericStore() *kallax.Store

GenericStore returns the generic store of this store.

func (*QueuedElementStore) Insert

func (s *QueuedElementStore) Insert(record *QueuedElement) error

Insert inserts a QueuedElement in the database. A non-persisted object is required for this operation.

func (*QueuedElementStore) MustCount

func (s *QueuedElementStore) MustCount(q *QueuedElementQuery) int64

MustCount returns the number of rows that would be retrieved with the given query, but panics if there is an error.

func (*QueuedElementStore) MustFind

MustFind returns the set of results for the given query, but panics if there is any error.

func (*QueuedElementStore) MustFindOne

MustFindOne returns the first row retrieved by the given query. It panics if there is an error or if there are no rows.

func (*QueuedElementStore) Reload

func (s *QueuedElementStore) Reload(record *QueuedElement) error

Reload refreshes the QueuedElement with the data in the database and makes it writable.

func (*QueuedElementStore) Save

func (s *QueuedElementStore) Save(record *QueuedElement) (updated bool, err error)

Save inserts the object if the record is not persisted, otherwise it updates it. Same rules of Update and Insert apply depending on the case.

func (*QueuedElementStore) SetGenericStore

func (s *QueuedElementStore) SetGenericStore(store *kallax.Store)

SetGenericStore changes the generic store of this store.

func (*QueuedElementStore) Transaction

func (s *QueuedElementStore) Transaction(callback func(*QueuedElementStore) error) error

Transaction executes the given callback in a transaction and rollbacks if an error is returned. The transaction is only open in the store passed as a parameter to the callback.

func (*QueuedElementStore) Update

func (s *QueuedElementStore) Update(record *QueuedElement, cols ...kallax.SchemaField) (updated int64, err error)

Update updates the given record on the database. If the columns are given, only these columns will be updated. Otherwise all of them will be. Be very careful with this, as you will have a potentially different object in memory but not on the database. Only writable records can be updated. Writable objects are those that have been just inserted or retrieved using a query with no custom select fields.

Jump to

Keyboard shortcuts

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