tmodel

package
v0.0.0-...-8d2fcc7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tmodel ...

Index

Constants

View Source
const (
	// CompletedTaskIndex is a index name which is required for
	// to build index for completed tasks
	CompletedTaskIndex = "CompletedTaskIndex"
	//CompletedTaskTable is a Table name for Completed Task
	CompletedTaskTable = "CompletedTask"
)

Variables

This section is empty.

Functions

func DeleteTaskFromDB

func DeleteTaskFromDB(ctx context.Context, t *Task) error

DeleteTaskFromDB is to delete the task from db Takes:

t of type pointer to Task object

Returns:

err of type error
On Success - return nil value
On Failure - return non nill value

func GetAllTaskKeys

func GetAllTaskKeys(ctx context.Context) ([]string, error)

GetAllTaskKeys will collect all task keys available in the DB Takes:

None

Returns:

Slice of type strings and error
On Success - error is set to nil and returns slice of tasks
On Failure - error is set to appropriate reason why it got failed
and slice of task is set to nil

func GetWriteConnection

func GetWriteConnection() *db.Conn

GetWriteConnection returns write connection retrieved from the connection pool.

func PersistTask

func PersistTask(ctx context.Context, t *Task, db common.DbType) error

PersistTask is to store the task data in db Takes:

t pointer to Task to be stored.
db of type common.DbType(int32)

func Transaction

func Transaction(ctx context.Context, key string, cb func(context.Context, string) error) error

Transaction - is for performing atomic oprations using optimitic locking

func ValidateTaskUserName

func ValidateTaskUserName(ctx context.Context, userName string) error

ValidateTaskUserName validates the username. Returns error with non nil value if username is not found in the db, if username found in the db error is set to nil.

Types

type CompletedTask

type CompletedTask struct {
	UserName string
	ID       string
	EndTime  int64
}

CompletedTask is used to build index for redis

type Message

type Message struct {
	Message           string   `json:"Message"`
	MessageID         string   `json:"MessageId"`
	MessageArgs       []string `json:"MessageArgs"`
	Oem               Oem      `json:"Oem"`
	RelatedProperties []string `json:"RelatedProperties"`
	Resolution        string   `json:"Resolution"`
	Severity          string   `json:"Severity"`
}

Message Model

type Oem

type Oem struct {
}

Oem Model

type Payload

type Payload struct {
	HTTPHeaders   map[string]string `json:"HttpHeaders"`
	HTTPOperation string            `json:"HttpOperation"`
	JSONBody      string            `json:"JsonBody"`
	TargetURI     string            `json:"TargetUri"`
}

Payload contain information detailing the HTTP and JSON payload information for executing the task. This object shall not be included in the response if the HidePayload property is set to True.

type Task

type Task struct {
	ParentID     string
	ChildTaskIDs []string
	ID           string
	URI          string
	UserName     string
	Name         string
	HidePayload  bool
	Payload      Payload
	/*The value of this property shall indicate the completion progress of
	the task, reported in percent of completion.
	If the task has not been started, the value shall be zero.
	*/
	PercentComplete int32
	TaskMonitor     string
	TaskState       string
	TaskStatus      string
	StatusCode      int32
	TaskResponse    []byte
	Messages        []*Message // Its there in the spec, how are we going to use it
	StartTime       time.Time
	EndTime         time.Time
}

Task Model to be moved to dmtf

func GetTaskStatus

func GetTaskStatus(ctx context.Context, taskID string, db common.DbType) (*Task, error)

GetTaskStatus is to retrieve the task data already present in db Takes:

taskID of type string contains the task ID of the task to be retrieved from the db
db of type common.DbType(int32)

Returns:

err of type error
	On Success - return nil value
	On Failure - return non nill value
t of type *Task implicitly valid only when error is nil

type Tick

type Tick struct {
	Ticker    *time.Ticker
	M         sync.Mutex
	Commit    bool
	Executing bool
}

Tick struct is used to help the goroutines that process the task queue to communicate effectively Tick contains the following attributes

1. Ticker is of type Ticker in time package. it is used to acknowledge the function that process task queue that it is time to commit the current pipelined transaction to redis DB 2. M is of type Mutex in sync package. It ensures only one goroutine access the Commit and Executing flags at the same time. 3. Commit is a flag which is made true when ticker "ticks". when it is made true, "ProcessTaskQueue" commit the current pipeline to redis. 4. Executing is a flag which is made true when the "ProcessTaskQueue" function is invoked and made false when it is finished.

func (*Tick) ProcessTaskQueue

func (tick *Tick) ProcessTaskQueue(queue *chan *Task, conn *db.Conn)

ProcessTaskQueue dequeue the tasks details from queue and update DB using pipelined transaction the pipeline is committed when signal task is dequeued from the queue a signal task is enqueued by the caller once in a millisecond

ProcessTaskQueue takes the following keys as input:

1."queue" is a pointer to the channel which acts as the task queue 2."conn" is an instance of Conn struct in persistence manager library

Jump to

Keyboard shortcuts

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