Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Sergey Petrenko <sergepetrenko@tarantool.org>,
	tarantool-patches@freelists.org,
	Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [tarantool-patches] Re: [PATCH] Replace net.box usage with console in tarantoolctl eval
Date: Mon, 9 Jul 2018 12:53:00 +0300	[thread overview]
Message-ID: <76d1c572-abd4-9bd7-77c1-0ab42466c938@tarantool.org> (raw)
In-Reply-To: <31c3604f-5ca6-23fb-039b-b08382fa4c8a@tarantool.org>

Hello. Thanks for the fixes! See my comment below.

The patch LGTM now. Vova, please, make a second review.

>>> diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in
>>> index 507ebe8bf..463d3e0a1 100755
>>> --- a/extra/dist/tarantoolctl.in
>>> +++ b/extra/dist/tarantoolctl.in
>>> @@ -647,13 +647,29 @@ local function stdin_isatty()
>>>   end
>>>     local function execute_remote(uri, code)
>>> -    local remote = netbox.connect(uri, {
>>> -        console = true, connect_timeout = TIMEOUT_INFINITY
>>> -    })
>>> -    if remote == nil then
>>> -        return nil
>>> +    local err, ret
>>> +    console.on_start(function(self)
>>> +        local cmd = string.format(
>>> +            "require('console').connect('%s', { connect_timeout = %s })",
>>> +            uri, TIMEOUT_INFINITY
>>> +        )
>>> +        err = self:eval(cmd)
>>
>> 1. Please, explain why do we connect in such complicated way? Why not just
>>
>>     console.connect(uri, {connect_timeout = TIMEOUT_INFINITY})
> I copied this connection method from function enter(), because console.connect()
> didn't work for me for some reason (probably did something wrong).

Console.connect works only when a console is started. See console.connect source.
Console.start creates internal console object and puts it into the fiber local
storage. Then this object is used by console.connect().

In 'tarantool>' interactive console you do not execute console.start because it
is started already, but in scripts you should start it explicitly, like that:

     console.start()
     console.on_start(do something with console and stop it)

> diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in
> index 507ebe8bf..3b1c38585 100755
> --- a/extra/dist/tarantoolctl.in
> +++ b/extra/dist/tarantoolctl.in
> @@ -647,13 +647,19 @@ local function stdin_isatty()
>   end
> 
>   local function execute_remote(uri, code)
> -    local remote = netbox.connect(uri, {
> -        console = true, connect_timeout = TIMEOUT_INFINITY
> -    })
> -    if remote == nil then
> -        return nil
> -    end
> -    return true, remote:eval(code)
> +    local status, ret
> +    console.on_start(function(self)
> +        status, ret = pcall(console.connect, uri,
> +                            {connect_timeout = TIMEOUT_INFINITY})
> +        if status then
> +            status, ret = pcall(self.eval, self, code)
> +        end
> +        self.running = false
> +    end)
> +    console.on_client_disconnect(function(self) self.running = false end)
> +
> +    console.start()
> +    return status, ret
>   end

      reply	other threads:[~2018-07-09  9:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  9:59 [tarantool-patches] " Serge Petrenko
2018-07-05 11:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-06 13:02   ` Sergey Petrenko
2018-07-09  9:53     ` Vladislav Shpilevoy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76d1c572-abd4-9bd7-77c1-0ab42466c938@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] Re: [PATCH] Replace net.box usage with console in tarantoolctl eval' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox