当使用eventlet运行celery时,Fabric失败并且名称查找失败

时间:2022-09-29 19:15:52

I have a celery task to run a sudo command on a remote machine using fabric:

我有一个芹菜任务,使用fabric在远程机器上运行sudo命令:

@app.task(soft_time_limit=600)
def run_puppet_agent(hostname):
    try:
        fabric_client = Fabric(hostname)
        result = fabric_client.run_command('puppet agent -t', True, True)
        if result.return_code == 0 or result.return_code == 2:
                return True, 'Puppet agent run successfully'
        else:
            raise Exception('Command %s run failed with a non zero or non-2 error code, '
                            '0 and 2 are status codes for successful puppet runs, returned     code %s'
                            % ('sudo puppet agent -t', result.return_code))
    except SoftTimeLimitExceeded:
        raise Exception('Puppet agent run took more than 600 seconds')
    except Exception as e:
        #run_puppet_agent.retry(args=[hostname], countdown=20)
        LOG.info('')
        raise Exception('Puppet agent failed with error message %s' % e.message)

if I run the celery workers as:

如果我把芹菜工人当作:

celery -A phantom.celery.manage worker --loglevel=info

it works fine !! But when I run the workers with eventlet as:

它工作正常!!但是,当我使用eventlet运行worker时:

celery -A phantom.celery.manage worker --loglevel=info -P eventlet -c 15

It goes terribly bad and gives me this exception:

它非常糟糕,给了我这个例外:

[WARNING/MainProcess] File     "/Users/uruddarraju/Phantom/phantom/tasks/fabric_tasks.py", line 19, in run_puppet_agent
[WARNING/MainProcess] result = fabric_client.run_command('puppet agent -t', True, True)
[WARNING/MainProcess] File "/Users/uruddarraju/Phantom/phantom/util/fabric/fabric_util.py", line 43, in run_command
[WARNING/MainProcess] return sudo(command, quiet=False)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 639, in host_prompting_wrapper
[WARNING/MainProcess] return func(*args, **kwargs)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/operations.py", line 1095, in sudo
[stderr=stderr, timeout=timeout, shell_escape=shell_escape,
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/operations.py", line 909, in _run_command
[WARNING/MainProcess] channel=default_channel(), command=wrapped_command, pty=pty,
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/state.py", line 390, in default_channel
[WARNING/MainProcess] chan = _open_session()
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/state.py", line 382, in _open_session
[WARNING/MainProcess] return connections[env.host_string].get_transport().open_session()
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 151, in __getitem__
[WARNING/MainProcess] self.connect(key)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 143, in connect
[WARNING/MainProcess] self[key] = connect(user, host, port, cache=self)
[WARNING/MainProcess] File "/Library/Python/2.7/site-packages/fabric/network.py", line 533, in connect
[WARNING/MainProcess] raise NetworkError('Name lookup failed for %s' % host, e)
[WARNING/MainProcess] NetworkError: Name lookup failed for <hostname>

WARNING/MainProcess] None

警告/主程序]无

FYI: I have other tasks that have different HTTP API calls and hence though eventlet would help but not working for me in this case

仅供参考:我有其他任务有不同的HTTP API调用,因此虽然eventlet会有所帮助但在这种情况下不适合我

1 个解决方案

#1


0  

I used gevent instead to work...solved my problem !! Thanks for the help though

我用gevent代替工作......解决了我的问题!!谢谢你的帮助

#1


0  

I used gevent instead to work...solved my problem !! Thanks for the help though

我用gevent代替工作......解决了我的问题!!谢谢你的帮助