|
- package fifo
-
- import "strings"
-
- const (
- CLOUD string = "Cloud"
- AI string = "Ai"
- HPC string = "Hpc"
- )
-
- type TaskFIFO struct {
- Queues []*Queue
- }
-
- // NewChannel 初始化队列
- func NewChannel() *TaskFIFO {
- channel := TaskFIFO{
- Queues: []*Queue{
- {
- ResourceType: CLOUD,
- },
- {
- ResourceType: AI,
- },
- {
- ResourceType: HPC,
- },
- },
- }
-
- return &channel
- }
-
- // SelectQueue 根据资源类型查询队列数组
- func (c *TaskFIFO) SelectQueue(resourceType string) *Queue {
- for _, queue := range c.Queues {
- if strings.EqualFold(queue.ResourceType, resourceType) {
- return queue
- }
- }
- return nil
- }
-
- func main() {
- channel := NewChannel()
- cloudQueue := channel.SelectQueue("cloud")
-
- dataList := []IData{
- &Data{
- TaskType: "cloud",
- Data: &Cloud{}},
- }
-
- cloudQueue.Push(&dataList)
-
- println(len(dataList))
- }
|