ec2实例上的python gearman worker没有响应

时间:2018-10-23 16:25:41

标签: python amazon-web-services amazon-ec2 gearman

我有两个AWS EC2实例。客户端在第一个ec2实例上运行,而worker在第二个ec2实例上运行。但是第二个ec2实例上的worker没有响应客户端的工作,甚至没有引发任何错误。

client.py:

import python3_gearman as gearman
def check_request_status(job_request):
    if job_request.complete:
    print("Job %s finished!  Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result))
    elif job_request.timed_out:
    print("Job %s timed out!" % job_request.unique)
    elif job_request.state == JOB_UNKNOWN:
    print("Job %s connection failed!" % job_request.unique)

gm_client = gearman.GearmanClient(['34.253.103.1:4730'])  # 34.253.103.1 :- ip address of worker

completed_job_request = gm_client.submit_job("reverse", "Hello World!")
check_request_status(completed_job_request)

worker.py:

import python3_gearman as gearman
gm_worker = gearman.GearmanWorker(['46.51.130.13:4730'])  # 46.51.130.13 :- ip address of client

def task_listener_reverse(gearman_worker, gearman_job):
    print('Reversing string: ' + gearman_job.data)
    return gearman_job.data[::-1]

# gm_worker.set_client_id is optional
gm_worker.set_client_id('python-worker')
gm_worker.register_task('reverse', task_listener_reverse)

# Enter our work loop and call gm_worker.after_poll() after each time we timeout/see socket activity
gm_worker.work()

在两个实例上都使用下面的命令来运行齿轮传动:

sudo gearmand --listen=0.0.0.0 -d

请建议上面的方法/代码出了什么问题。

0 个答案:

没有答案