models

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobNoOfTasksPath                    = "/number-of-tasks"
	JobStatePath                        = "/state"
	JobTotalSearchDocumentsPath         = "/total_search_documents"
	JobURLExtractionCompletedStatusPath = "/url_extraction_completed"
)

Paths of fields in a job resource

View Source
const (
	JobETagKey                         = "e_tag"
	JobIDJSONKey                       = "id"
	JobLastUpdatedKey                  = "last_updated"
	JobNoOfTasksKey                    = "number_of_tasks"
	JobReindexCompletedKey             = "reindex_completed"
	JobReindexFailedKey                = "reindex_failed"
	JobReindexStartedKey               = "reindex_started"
	JobSearchIndexNameKey              = "search_index_name"
	JobStateKey                        = "state"
	JobTotalSearchDocumentsKey         = "total_search_documents"
	JobTotalInsertedSearchDocumentsKey = "total_inserted_search_documents"
	JobURLExtractionCompletedKey       = "url_extraction_completed"
)

BSON and JSON keys for each field in the job resource

View Source
const (
	JobLinksTasksKey = "links: tasks"
	JobLinksSelfKey  = "links: self"
)

Reference keys for each field in the JobLinks resource for component testing

View Source
const (
	JobStateCreated    = "created" // this is the default value of state in a new job
	JobStateCompleted  = "completed"
	JobStateFailed     = "failed"
	JobStateInProgress = "in-progress"
)

JOB STATE - Possible values of a job's state

Variables

View Source
var (
	JobUUID = func() string {
		return uuid.NewV4().String()
	}
	NewJobID = JobUUID
)

NewJobID returns a unique UUID for a job resource and this can be used to mock the ID in tests

View Source
var (
	// ValidJobStates is used for logging available job states
	ValidJobStates = []string{
		JobStateCreated,
		JobStateCompleted,
		JobStateFailed,
		JobStateInProgress,
	}

	// ValidJobStatesMap is used for searching available job states
	ValidJobStatesMap = map[string]bool{
		JobStateCreated:    true,
		JobStateCompleted:  true,
		JobStateFailed:     true,
		JobStateInProgress: true,
	}
)

Functions

func GenerateETagForJob added in v0.16.0

func GenerateETagForJob(ctx context.Context, updatedJob Job) (eTag string, err error)

GenerateETagForJob generates a new eTag for a job resource

func GenerateETagForJobs added in v0.21.0

func GenerateETagForJobs(ctx context.Context, jobs Jobs) (eTag string, err error)

GenerateETagForJobs generates a new eTag for a jobs resource

func GenerateETagForTask added in v0.18.0

func GenerateETagForTask(ctx context.Context, task Task) (eTag string, err error)

GenerateETagForTask generates a new eTag for a task resource

func GenerateETagForTasks added in v0.21.0

func GenerateETagForTasks(ctx context.Context, tasks Tasks) (eTag string, err error)

GenerateETagForTasks generates a new eTag for a tasks resource

func ParseTaskName added in v0.11.0

func ParseTaskName(taskName string, taskNames map[string]bool) error

ParseTaskName returns ErrTaskInvalidName if it cannot find a valid task name matching the given taskName string

Types

type Job

type Job struct {
	ETag                         string    `bson:"e_tag"                            json:"-"`
	ID                           string    `bson:"_id"                              json:"id"`
	LastUpdated                  time.Time `bson:"last_updated"                     json:"last_updated"`
	Links                        *JobLinks `bson:"links"                            json:"links"`
	NumberOfTasks                int       `bson:"number_of_tasks"                  json:"number_of_tasks"`
	ReindexCompleted             time.Time `bson:"reindex_completed"                json:"reindex_completed"`
	ReindexFailed                time.Time `bson:"reindex_failed"                   json:"reindex_failed"`
	ReindexStarted               time.Time `bson:"reindex_started"                  json:"reindex_started"`
	SearchIndexName              string    `bson:"search_index_name"                json:"search_index_name"`
	State                        string    `bson:"state"                            json:"state"`
	TotalSearchDocuments         int       `bson:"total_search_documents"           json:"total_search_documents"`
	TotalInsertedSearchDocuments int       `bson:"total_inserted_search_documents"  json:"total_inserted_search_documents"`
	URLExtractionCompleted       bool      `bson:"url_extraction_completed"  json:"url_extraction_completed"`
}

Job represents a job metadata model and json representation for API

func NewJob

func NewJob(ctx context.Context, searchIndexName string) (*Job, error)

NewJob returns a new Job resource that it creates and populates with default values.

type JobLinks struct {
	Tasks string `json:"tasks"`
	Self  string `json:"self"`
}

JobLinks is a type that contains links to the endpoints for returning a specific job (self), and the tasks that it contains (tasks), respectively.

type Jobs added in v0.4.0

type Jobs struct {
	Count      int   `bson:"count,omitempty"        json:"count"`
	JobList    []Job `bson:"jobs,omitempty"         json:"jobs"`
	Limit      int   `bson:"limit,omitempty"        json:"limit"`
	Offset     int   `bson:"offset,omitempty"       json:"offset"`
	TotalCount int   `bson:"total_count,omitempty"  json:"total_count"`
}

Jobs represents an array of Job resources and json representation for API

type ReindexRequested added in v0.15.0

type ReindexRequested struct {
	JobID       string `avro:"job_id"`
	SearchIndex string `avro:"search_index"`
	TraceID     string `avro:"trace_id"`
}

ReindexRequested provides an avro structure for a Reindex Requested event

type Task added in v0.9.0

type Task struct {
	JobID             string     `bson:"job_id" json:"job_id"`
	LastUpdated       time.Time  `bson:"last_updated" json:"last_updated"`
	Links             *TaskLinks `bson:"links" json:"links"`
	NumberOfDocuments int        `bson:"number_of_documents" json:"number_of_documents"`
	TaskName          string     `bson:"task_name" json:"task_name"`
	ETag              string     `bson:"e_tag" json:"-"`
}

Task represents a job metadata model and json representation for API

func NewTask added in v0.9.0

func NewTask(ctx context.Context, jobID string, taskToCreate *TaskToCreate) (*Task, error)

NewTask returns a new Task resource that it creates and populates with default values.

type TaskLinks struct {
	Self string `json:"self"`
	Job  string `json:"job"`
}

TaskLinks is a type that contains links to the endpoints for returning a specific task (self), and the job that it is part of (job), respectively.

type TaskToCreate added in v0.9.0

type TaskToCreate struct {
	TaskName          string `json:"task_name"`
	NumberOfDocuments int    `json:"number_of_documents"`
}

TaskToCreate is a type that contains the details required for creating a Task type.

func (TaskToCreate) Validate added in v0.9.0

func (task TaskToCreate) Validate(taskNames map[string]bool) error

Validate checks that the TaskToCreate contains a valid TaskName that is not an empty string.

type Tasks added in v0.12.0

type Tasks struct {
	Count      int    `bson:"count,omitempty"        json:"count"`
	TaskList   []Task `bson:"jobs,omitempty"         json:"tasks"`
	Limit      int    `bson:"limit,omitempty"        json:"limit"`
	Offset     int    `bson:"offset,omitempty"       json:"offset"`
	TotalCount int    `bson:"total_count,omitempty"  json:"total_count"`
}

Tasks represents an array of Task resources and json representation for API

Jump to

Keyboard shortcuts

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