models

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JobPriority are the priorities to use for jobs
	JobPriorityHighest  = 10
	JobPriorityHigh     = 8
	JobPriorityStandard = 5
	JobPriorityLow      = 3
	JobPriorityLowest   = 1
)
View Source
const (
	// JobTypeUnknown is reserved and unused
	JobTypeUnknown jobTypeEnum = iota

	// JobTypeAddChannel is the job for adding a new Slack channel
	JobTypeAddChannel

	// JobTypeUpdateChannel is the job for updating settings for a Slack channel
	JobTypeUpdateChannel

	// JobTypeDeleteChannel is the job for deleting a Slack channel
	JobTypeDeleteChannel

	// JobTypeSyncChannels is the job for syncing Slack channels with the database
	JobTypeSyncChannels

	// JobTypeAddMember is the job for adding a new Slack member for a channel
	JobTypeAddMember

	// JobTypeUpdateMember is the job for updating a Slack member for a channel
	JobTypeUpdateMember

	// JobTypeGreetMember is the job for greeting a new Slack member for a channel
	JobTypeGreetMember

	// JobTypeDeleteMember is the job for deleting a Slack member for a channel
	JobTypeDeleteMember

	// JobTypeSyncMembers is the job for syncing Slack members with the database
	JobTypeSyncMembers

	// JobTypeCreateRound is the job for starting a new chat roulette round for a channel
	JobTypeCreateRound

	// JobTypeEndRound is the job for ending a running chat roulette round for a channel
	JobTypeEndRound

	// JobTypeCreateMatches is the job for creating matches for a round of chat roulette
	JobTypeCreateMatches

	// JobTypeUpdateMatch is the job for updating the status of a match at the end of a round of chat roulette
	JobTypeUpdateMatch

	// JobTypeCreatePair is the job for creating a pair for a round of chat roulette
	JobTypeCreatePair

	// JobTypeNotifyPair is the job for notifying a pair for a round of chat roulette
	JobTypeNotifyPair

	// JobTypeCheckPair is the job for checking if a pair has met for a round of chat roulette
	JobTypeCheckPair

	// JobTypeReportStats is the job for generating report for a chat roulette round
	JobTypeReportStats
)
View Source
const (
	// JobStatusUnknown is reserved and unused
	JobStatusUnknown jobStatusEnum = iota

	// JobStatusPending is the default status for new jobs and jobs waiting to be retried
	JobStatusPending

	// JobStatusErrored is the status for a job that has hit an error, but can be retried
	JobStatusErrored

	// JobStatusCanceled is the status when a job is canceled
	JobStatusCanceled

	// JobStatusFailed is the status when a job has failed and would not succeed even if retried
	JobStatusFailed

	// JobStatusSucceeded is the status when a job has completed successfully
	JobStatusSucceeded
)

Variables

View Source
var (
	// ErrInvalidJobType is returned when an invalid job type is used
	ErrInvalidJobType = errors.New("invalid job type")

	// ErrInvalidJobStatus is returned when an invalid job status is used
	ErrInvalidJobStatus = errors.New("invalid job status")
)
View Source
var (
	// ErrInvalidInterval is returned when an invalid chat roulette interval is used
	ErrInvalidInterval = errors.New("invalid chat roulette interval")
)

Functions

func ExtractJobFromActionID

func ExtractJobFromActionID(actionID string) (jobTypeEnum, error)

ExtractJobFromActionID extracts the job type from a Slack action ID

func FormatSlackActionID

func FormatSlackActionID(key jobTypeEnum, value interface{}) string

FormatSlackActionID creates a pipe ("|") separated Slack action ID string consisting of the job type as the key and an arbitrary value to uniquely identify an interactive Slack component.

func JobRequiresSlackChannel

func JobRequiresSlackChannel(jobType jobTypeEnum) bool

Types

type Channel

type Channel struct {
	// ChannelID is the ID of the Slack channel
	ChannelID string `gorm:"primaryKey"`

	// Inviter is the ID of the user who has invited the bot to the Slack channel
	Inviter string

	// Interval is the interval for chat roulette rounds for the channel (ie. weekly, biweekly, triweekly, monthly)
	Interval IntervalEnum

	// Weekday is the weekday in which new chat roulette rounds are started for the channel (ie. Sunday, Monday, etc.)
	Weekday time.Weekday

	// Hour is the hour in which new chat roulette rounds are started for the channel (ie. 10, 12, 18)
	Hour int

	// NextRound is the timestamp of the next chat roulette round
	NextRound time.Time

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time

	// UpdatedAt is the timestamp of when the record was last updated
	UpdatedAt time.Time
}

Channel represents a row in the channels table

type GenericJob

type GenericJob[T any] struct {
	// JobType is the type of background job.
	JobType jobTypeEnum
	// Params are the parameters for the job.
	// This must match the job type.
	Params T
	// Priority is the priority in the queue.
	// This is optional and will default to JobPriorityStandard.
	Priority int
	// ExecAt is the execution time.
	// This is optional and will default to time.Now().
	ExecAt time.Time
}

GenericJob is the generic representation of a background job with job parameters, priority, and execution time.

type IntervalEnum

type IntervalEnum int64

IntervalEnum is an enum for chat roulette intervals

const (
	// Weekly is every 7 days
	Weekly IntervalEnum = 7

	// Biweekly is every 2 weeks, 14 days
	Biweekly IntervalEnum = 14

	// Triweekly is every 3 weeks, 21 days
	Triweekly IntervalEnum = 21

	// Monthly is every 4 weeks, 28 days
	Monthly IntervalEnum = 28
)

func ParseInterval

func ParseInterval(s string) (IntervalEnum, error)

ParseInterval parses a chat roulette interval given by its name.

func (*IntervalEnum) Scan

func (i *IntervalEnum) Scan(value interface{}) error

Scan implements the Scanner interface

func (IntervalEnum) String

func (i IntervalEnum) String() string

func (IntervalEnum) Value

func (i IntervalEnum) Value() (driver.Value, error)

Value implements the Valuer interface

type Job

type Job struct {
	// ID is the primary key of the record
	ID int32 `gorm:"primaryKey"`

	// JobID is the unique ID for the job
	JobID ksuid.KSUID `gorm:"column:job_id"`

	// JobType is the type of job
	JobType jobTypeEnum

	// Priority is the execution priority (1 - 10) for the job in the queue, with 10 being highest
	Priority int

	// Status is the completion status (success, failed, etc.) for a job
	Status jobStatusEnum

	// IsCompleted is a boolean flag for checking if the job has been completed
	IsCompleted bool

	// Data is the JSON data for the job
	Data datatypes.JSON

	// ExecAt is the timestamp of when the job should be executed
	ExecAt time.Time

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time

	// UpdatedAt is the timestamp of when the record was last updated
	UpdatedAt time.Time
}

Job represents a row in the jobs table

func NewJob

func NewJob(jobType jobTypeEnum, data datatypes.JSON) *Job

NewJob creates a new *Job that will be scheduled with standard execution priority.

type Match

type Match struct {
	// ID is the primary key for the table
	ID int32 `gorm:"primaryKey"`

	// RoundID is the ID of the chat roulette round
	RoundID int32 `gorm:"foreignKey:RoundID;references:Round"`

	// MpimID is the ID of the Slack group DM
	MpimID string `gorm:"column:mpim_id"`

	// HasMet is a boolean flag for if the match has met for chat roulette
	HasMet bool

	// WasNotified is a boolean flag for if the match has been notified
	WasNotified bool

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time

	// UpdatedAt is the timestamp of when the record was last updated
	UpdatedAt time.Time
}

Match represents a row in the matches table

type Member

type Member struct {
	// ID is the primary key for the table
	ID int32 `gorm:"primaryKey"`

	// UserID is the ID of the Slack user
	UserID string

	// ChannelID is the ID of the Slack channel that the user is a member of
	ChannelID string `gorm:"foreignKey:ChannelID;references:Channel"`

	// Country is the country in which the Slack user resides
	Country sqlcrypter.EncryptedBytes

	// City is the city in which the Slack user resides
	City sqlcrypter.EncryptedBytes

	// Timezone is the timezone that the Slack user is in
	Timezone sqlcrypter.EncryptedBytes

	// ProfileType is the Slack user's social profile type
	ProfileType sqlcrypter.EncryptedBytes

	// ProfileLink is the link to the Slack user's social profile
	ProfileLink sqlcrypter.EncryptedBytes

	// CalendlyLink is a link for the user's Calendly
	CalendlyLink sqlcrypter.EncryptedBytes

	// IsActive is a boolean flag for if the user is participating in chat roulette
	//
	// A pointer is used here to ensure non-zero value (ie. false) is saved.
	IsActive *bool

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time

	// UpdatedAt is the timestamp of when the record was last updated
	UpdatedAt time.Time
}

Member represents a row in the members table

type Pairing

type Pairing struct {
	// ID is an auto-incrementing identifier for the table
	ID int32 `gorm:"autoIncrement"`

	// MatchID is the ID of the chat roulette match
	MatchID int32 `gorm:"primaryKey;foreignKey:MatchID;references:Match"`

	// MemberID is the ID of the Slack user in this chat roulette match
	MemberID int32 `gorm:"primaryKey;foreignKey:MemberID;references:Members"`

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time
}

Pairing represents a row in the pairings table

type Round

type Round struct {
	// ID is the primary key for the table
	ID int32 `gorm:"primaryKey"`

	// ChannelID is the ID of the Slack channel for this round
	ChannelID string `gorm:"foreignKey:ChannelID;references:Channel"`

	// HasEnded is a boolean flag for if the chat roulette round has concluded
	HasEnded bool

	// CreatedAt is the timestamp of when the record was first created
	CreatedAt time.Time

	// UpdatedAt is the timestamp of when the record was last updated
	UpdatedAt time.Time
}

Round represents a row in the rounds table

Jump to

Keyboard shortcuts

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