Documentation
¶
Index ¶
- Constants
- func GenerateToken() string
- func IsLocal(hostname string) bool
- func IsValidFilename(name string) bool
- func IsValidJobStatus(v string) bool
- func IsValidJobType(v string) bool
- func NewContext(ctx context.Context, user *User) context.Context
- type Error
- type File
- type FileService
- type Job
- type JobExecutor
- type JobScheduler
- type JobService
- type Playlist
- type PlaylistService
- type SMS
- type SMSService
- type TTSService
- type Track
- type TrackService
- type URLTrackGenerator
- type User
- type UserService
Constants ¶
const ( ErrInternal = Error("internal error") )
General errors.
const ( ErrFilenameRequired = Error("filename required") ErrInvalidFilename = Error("invalid filename") )
File errors
const ( ErrJobRequired = Error("job required") ErrJobNotFound = Error("job not found") ErrJobOwnerRequired = Error("job owner required") ErrJobOwnerNotFound = Error("job owner not found") ErrInvalidJobType = Error("invalid job type") ErrInvalidJobStatus = Error("invalid job status") )
Job errors.
const ( JobTypeCreateTrackFromURL = "create_track_from_url" JobTypeCreateTrackFromTTS = "create_track_from_tts" )
Job types.
const ( JobStatusPending = "pending" JobStatusProcessing = "processing" JobStatusCompleted = "completed" JobStatusFailed = "failed" )
Job statuses.
const ( ErrPlaylistRequired = Error("playlist required") ErrPlaylistNotFound = Error("playlist not found") ErrPlaylistOwnerRequired = Error("playlist owner required") ErrPlaylistTokenRequired = Error("playlist token required") ErrPlaylistNameRequired = Error("playlist name required") )
Playlist errors.
const ( ErrTrackRequired = Error("track required") ErrTrackNotFound = Error("track not found") ErrTrackPlaylistRequired = Error("track playlist required") ErrTrackFilenameRequired = Error("track filename required") ErrTrackTitleRequired = Error("track title required") )
Track errors.
const ( ErrUserRequired = Error("user required") ErrUserNotFound = Error("user not found") ErrUserMobileNumberInUse = Error("mobile number already in use") ErrUserMobileNumberRequired = Error("mobile number required") )
User errors.
const DefaultPlaylistName = "My Peapod"
const (
ErrInvalidURL = Error("invalid url")
)
General errors.
Variables ¶
This section is empty.
Functions ¶
func IsLocal ¶
IsLocal returns true if the host represents the local machine. This function assumes the hostname has no port.
func IsValidFilename ¶
IsValidFilename returns true if the name is in a valid format.
func IsValidJobStatus ¶
IsValidJobType returns true if v is a valid type.
func IsValidJobType ¶
IsValidJobType returns true if v is a valid type.
Types ¶
type FileService ¶
type FileService interface {
GenerateName(ext string) string
FindFileByName(ctx context.Context, name string) (*File, io.ReadCloser, error)
CreateFile(ctx context.Context, f *File, r io.Reader) error
}
FileService represents a service for managing file objects.
type Job ¶
type Job struct {
ID int `json:"id"`
OwnerID int `json:"owner_id"`
Owner *User `json:"owner,omitempty"`
Type string `json:"type"`
Status string `json:"status"`
PlaylistID int `json:"playlist_id,omitempty"`
Title string `json:"title"`
URL string `json:"url,omitempty"`
Text string `json:"text,omitempty"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Job represents an task to be performed by a worker.
type JobExecutor ¶
type JobExecutor struct {
FileService FileService
SMSService SMSService
TrackService TrackService
TTSService TTSService
URLTrackGenerator URLTrackGenerator
}
JobExecutor represents a worker that executes a job.
func (*JobExecutor) ExecuteJob ¶
func (e *JobExecutor) ExecuteJob(ctx context.Context, job *Job) error
ExecuteJob processes a single job.
type JobScheduler ¶
type JobScheduler struct {
FileService FileService
JobService JobService
SMSService SMSService
TrackService TrackService
TTSService TTSService
UserService UserService
URLTrackGenerator URLTrackGenerator
LogOutput io.Writer
// contains filtered or unexported fields
}
JobScheduler receives new jobs and schedules them for execution.
func NewJobScheduler ¶
func NewJobScheduler() *JobScheduler
NewJobScheduler returns a new instance of JobScheduler.
func (*JobScheduler) Close ¶
func (s *JobScheduler) Close() error
Close stops the job processing queue and waits for outstanding workers.
func (*JobScheduler) Open ¶
func (s *JobScheduler) Open() error
Open initializes the job processing queue.
type JobService ¶
type JobService interface {
// Notification channel when a new job is ready.
C() <-chan struct{}
CreateJob(ctx context.Context, job *Job) error
NextJob(ctx context.Context) (*Job, error)
CompleteJob(ctx context.Context, id int, err error) error
}
JobService manages jobs in a job queue.
type Playlist ¶
type Playlist struct {
ID int `json:"id"`
OwnerID int `json:"owner_id"`
Token string `json:"token"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Tracks []*Track `json:"tracks,omitempty"`
}
Playlist represents a time-ordered list of tracks.
func (*Playlist) LastTrackUpdatedAt ¶
LastTrackUpdatedAt returns maximum track time.
type PlaylistService ¶
type PlaylistService interface {
FindPlaylistByID(ctx context.Context, id int) (*Playlist, error)
FindPlaylistByToken(ctx context.Context, token string) (*Playlist, error)
FindPlaylistsByUserID(ctx context.Context, id int) ([]*Playlist, error)
}
PlaylistService represents a service for managing playlists.
type SMSService ¶
SMSService sends a text message to a recipient.
type TTSService ¶
type Track ¶
type Track struct {
ID int `json:"id"`
PlaylistID int `json:"playlist_id"`
Filename string `json:"filename"`
Title string `json:"title"`
Description string `json:"description"`
Duration time.Duration `json:"duration"`
ContentType string `json:"content_type"`
Size int `json:"size"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Track represents an audio track.
type TrackService ¶
type TrackService interface {
FindTrackByID(ctx context.Context, id int) (*Track, error)
CreateTrack(ctx context.Context, track *Track) error
}
TrackService represents a service for managing audio tracks.
type URLTrackGenerator ¶
type URLTrackGenerator interface {
GenerateTrackFromURL(ctx context.Context, url url.URL) (*Track, io.ReadCloser, error)
}
URLTrackGenerator returns a track and file contents from a URL.