[future] 修改celery 使用eventlet 作为concurrent pool, 添加获取资产硬件信息的 初步接口

pull/530/head
Administrator 8 years ago
parent fd945513ac
commit 97d7e6cb9b

@ -1,3 +1,5 @@
# ~*~ coding: utf-8 ~*~
#
from __future__ import unicode_literals

@ -1,9 +0,0 @@
from .tasks import longtime_add
import time
result = longtime_add.delay(1,2)
print 'Task finished? ', result.ready()
print 'Task result: ', result.result
time.sleep(10)
print 'Task finished? ', result.ready()
print 'Task result: ', result.result

@ -0,0 +1,17 @@
from __future__ import unicode_literals
from .tasks import get_asset_hardware_info
from celery.result import AsyncResult
def start_get_hardware_info(*assets):
result = get_asset_hardware_info.delay(*assets)
return result.id
def get_hardware_info(task_id):
result = AsyncResult(task_id)
if result.ready():
return {"Completed": False, "data": result.get()}
else:
return {"Completed": True, "data": None}

@ -1,17 +1,35 @@
from __future__ import absolute_import
import time
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from common import celery_app
from ops.ansible_api import Config, ADHocRunner
@shared_task
def longtime_add(x, y):
print 'long time task begins'
# sleep 5 seconds
time.sleep(5)
print 'long time task finished'
return x + y
@shared_task(name="get_asset_hardware_info")
def get_asset_hardware_info(*assets):
conf = Config()
play_source = {
"name": "Get host hardware information",
"hosts": "default",
"gather_facts": "no",
"tasks": [
dict(action=dict(module='setup'))
]
}
hoc = ADHocRunner(conf, play_source, *assets)
ext_code, result = hoc.run()
return ext_code, result
@shared_task(name="asset_test_ping_check")
def asset_test_ping_check():
pass
@shared_task(name="add_user_to_assert")
def add_user_to_asset():
pass
@celery_app.task(name='hello-world')

@ -23,4 +23,4 @@ sshpubkeys==2.2.0
djangorestframework-bulk==0.2.1
python-gssapi==0.6.4
tornado==4.4.2
eventlet==0.19.0

@ -29,7 +29,7 @@ def start_django():
def start_celery():
os.chdir(apps_dir)
print('start celery')
subprocess.call('celery -A common worker -l info', shell=True)
subprocess.call('celery -A common worker -P eventlet -l info', shell=True)
def main():

Loading…
Cancel
Save