tarantool queue attempt to index global 'queue'

375 Views Asked by At
  1. I have error in line: que := queue.New(conn, "foobar") : Error eval:1: attempt to index global 'queue' (a nil value) (0x20)

  2. Config file: (if i delete box.once then erros tube is exists) How to correct init users and tube in config, without error 'user already exist`?

`

box.cfg {listen=3303}
local queue = require('queue')
queue.start()
queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
box.once("init", function()
    box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

`

code: `

func TestTarantoolQueue(t *testing.T)  {
    //opts := tarantool.Opts{User: "test", Pass: "test"}
    opts := tarantool.Opts{}
    conn, err := tarantool.Connect("127.0.0.1:3303", opts)
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    cfg := queue.Cfg{
        Temporary: true,
        IfNotExists: true,
        Kind: queue.FIFO_TTL,
        Opts: queue.Opts{
            Ttl: 10 * time.Second,
            Ttr: 5 * time.Second,
            Delay: 3 * time.Second,
            Pri: 1,
        },
    }
    que := queue.New(conn, "foobar")
    err = que.Create(cfg)
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    task, err := que.Put("test_data")
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    fmt.Println("Task id is ", task.Id())
    task, err = que.Take() //blocking operation
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    fmt.Println("Data is ", task.Data())
    task.Ack()
    task, err = que.Put([]int{1, 2, 3})
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    task.Bury()
    task, err = que.TakeTimeout(2 * time.Second)
    if task == nil {
        fmt.Println("Task is nil")
    }
    que.Drop()
}

`

1

There are 1 best solutions below

0
On

Removing local from local queue = require('queue') should solve the problem.