Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]Job timeout #482

Open
sys9kdr opened this issue Apr 19, 2023 · 4 comments
Open

[Feature Request]Job timeout #482

sys9kdr opened this issue Apr 19, 2023 · 4 comments

Comments

@sys9kdr
Copy link

sys9kdr commented Apr 19, 2023

Commands in plenary.nvim's job sometimes take a long time to resolve, which can be frustrating for users. To address this, I propose adding a timeout option to the plugin's job feature. This would allow users to set a timeout for commands and automatically quit the command with an error message if it takes too long to execute.

local Job = require'plenary.job'

Job:new({
  command = 'someTooLongTimeCommand',
  args = { '--files' },
  cwd = '/usr/bin',
  env = { ['a'] = 'b' },
  on_exit = function(j, return_val)
    print(return_val)
    print(j:result())
  end,
  timeout = 5000 -- timout with ms
}):sync() -- or start()
@miversen33
Copy link
Contributor

FWIW, I have implemented this in my abstraction of spawn. Feel free to yoink this for plenary. Its basically just making everything async and "waiting" until a vim.loop.timer fires to kill the running job if its still running.

@sys9kdr
Copy link
Author

sys9kdr commented Apr 20, 2023

In my case, I use a wrapper to kill jobs by timeout.

wrapFunc = function(someFuncReturnPid, timeout)
    timeout = timeout or 5000
    local pid = someFuncReturnPid
    local timer = vim.loop.new_timer()
    timer:start(timeout, 0, function()
        vim.loop.kill(pid)
        print('job timeout')
    end)
end

I think that wrapper approach is redundant. So I want a timeout option.

@Conni2461
Copy link
Collaborator

@sys9kdr
Copy link
Author

sys9kdr commented Apr 21, 2023

Wouldn't it be more convenient to have timout in the job itself? I don't like using sync because of waiting time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants