database

package
v0.0.0-...-7dcd076 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoJobs indicates that no jobs can be found for a given parent ID.
	ErrNoJobs = errors.New("no jobs found with this parent ID")

	// ErrJobNotFound indicates that no job can be found for a given job ID.
	ErrJobNotFound = errors.New("job not found")
)

Functions

This section is empty.

Types

type ByCreatedAt

type ByCreatedAt []Job

ByCreatedAt implements sort.Interface for []Job by CreatedAt field.

func (ByCreatedAt) Len

func (b ByCreatedAt) Len() int

func (ByCreatedAt) Less

func (b ByCreatedAt) Less(i, j int) bool

func (ByCreatedAt) Swap

func (b ByCreatedAt) Swap(i, j int)

type DB

type DB interface {
	StoreJob(*Job) (string, error)
	UpdateJob(string, *Job) error
	GetJob(string) (*Job, error)
	DeleteJob(string) error
	GetJobs(string) ([]Job, error)
	GetJobByProviderID(string) (*Job, error)
}

DB interface for database interactions

type DatastoreClient

type DatastoreClient interface {
	Put(context.Context, *datastore.Key, interface{}) (*datastore.Key, error)
	Get(context.Context, *datastore.Key, interface{}) error
	Delete(context.Context, *datastore.Key) error
	GetAll(context.Context, *datastore.Query, interface{}) ([]*datastore.Key, error)
}

DatastoreClient is a datastore interface with operations used by the captions API

type DatastoreDatabase

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

DatastoreDatabase is a datastore client that implements DB interface

func NewDatastoreDatabase

func NewDatastoreDatabase(projectID string) (*DatastoreDatabase, error)

NewDatastoreDatabase returns a DatastoreDatabase

func (*DatastoreDatabase) DeleteJob

func (d *DatastoreDatabase) DeleteJob(id string) error

DeleteJob deletes a job from database

func (*DatastoreDatabase) GetJob

func (d *DatastoreDatabase) GetJob(id string) (*Job, error)

GetJob retrieves a job from database

func (*DatastoreDatabase) GetJobByProviderID

func (d *DatastoreDatabase) GetJobByProviderID(providerID string) (*Job, error)

GetJobByProviderID returns a job associated with a given provider ID

func (*DatastoreDatabase) GetJobs

func (d *DatastoreDatabase) GetJobs(parentID string) ([]Job, error)

GetJobs retrieves all jobs in database

func (*DatastoreDatabase) StoreJob

func (d *DatastoreDatabase) StoreJob(job *Job) (string, error)

StoreJob stores a job

func (*DatastoreDatabase) UpdateJob

func (d *DatastoreDatabase) UpdateJob(id string, job *Job) error

UpdateJob updates a job

type Job

type Job struct {
	ID             string         `json:"id"`
	ParentID       string         `json:"parent_id"`
	MediaURL       string         `json:"media_url"`
	Status         string         `json:"status"`
	Provider       string         `json:"provider"`
	ProviderParams ProviderParams `json:"provider_params"`
	CreatedAt      time.Time      `json:"created_at"`
	Outputs        []JobOutput    `json:"outputs"`
	Done           bool           `json:"done"`
	Language       string         `json:"language"`
	Details        string         `json:"details,omitempty"`
	CaptionFile    UploadedFile   `json:"caption_file,omitempty"`
	JobType        string         `json:"job_type"`
}

Job representation of a captions job

func (*Job) GetProviderID

func (j *Job) GetProviderID() string

func (*Job) UpdateStatus

func (j *Job) UpdateStatus(status, details string) bool

UpdateStatus update Job status and mark as done if needed

type JobOutput

type JobOutput struct {
	URL      string `json:"url"`
	Type     string `json:"type"`
	Filename string `json:"filename"`
}

JobOutput output associated with a Job

type JobSummary

type JobSummary struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
}

JobSummary minimal information about a Job

type MemoryDatabase

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

MemoryDatabase memory based database implementation for the DB interface

func NewMemoryDatabase

func NewMemoryDatabase() *MemoryDatabase

NewMemoryDatabase creates a MemoryDatabase

func (*MemoryDatabase) DeleteJob

func (db *MemoryDatabase) DeleteJob(id string) error

DeleteJob deletes a Job given its ID

func (*MemoryDatabase) GetJob

func (db *MemoryDatabase) GetJob(id string) (*Job, error)

GetJob returns a Job given its ID

func (*MemoryDatabase) GetJobByProviderID

func (db *MemoryDatabase) GetJobByProviderID(providerID string) (*Job, error)

GetJobByProviderID Returns returns a job matching the ProviderID

func (*MemoryDatabase) GetJobs

func (db *MemoryDatabase) GetJobs(parentID string) ([]Job, error)

GetJobs Returns all Jobs stored for the same ParentID

func (*MemoryDatabase) StoreJob

func (db *MemoryDatabase) StoreJob(job *Job) (string, error)

StoreJob stores Job in-memory

func (*MemoryDatabase) UpdateJob

func (db *MemoryDatabase) UpdateJob(id string, job *Job) error

UpdateJob updates Job in-memory

type ProviderJob

type ProviderJob struct {
	ID          string
	Status      string
	Details     string
	Params      map[string]string
	Cancellable bool
}

ProviderJob holds data coming from a Provider

type ProviderParams

type ProviderParams map[string]string

ProviderParams is a set of parameters for providers

func (*ProviderParams) Load

func (p *ProviderParams) Load(ps []datastore.Property) error

Load makes ProviderParams implement datastore.PropertyLoadSaver interface

func (*ProviderParams) Save

func (p *ProviderParams) Save() ([]datastore.Property, error)

Save makes ProviderParams implement datastore.PropertyLoadSaver interface

type UploadedFile

type UploadedFile struct {
	File []byte `json:"file" datastore:",noindex"`
	Name string `json:"name"`
}

UploadedFile contains the uploaded file and its name

Jump to

Keyboard shortcuts

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