Add external task for install monit
This commit is contained in:
parent
0b57bcab9b
commit
2ebe22f79e
6 changed files with 206 additions and 65 deletions
102
models/tasks.py
102
models/tasks.py
|
|
@ -55,6 +55,7 @@ class Task(WebModel):
|
|||
self.fields['where_sql_server'].escape=True
|
||||
|
||||
self.txt_error=''
|
||||
self.error=False
|
||||
|
||||
def run_task(self, server, path, name_task, codename_task, description_task, data={}, user='', password='', where_sql_server='', url='', ssh_key_priv='', ssh_key_password='', send_task=True):
|
||||
|
||||
|
|
@ -206,81 +207,54 @@ class Task(WebModel):
|
|||
result = q.enqueue(task, row['id'], job_timeout=3600)
|
||||
"""
|
||||
|
||||
return send_task_to_server(task_id)
|
||||
return self.send_task_to_server()
|
||||
|
||||
else:
|
||||
|
||||
#Enqueue task function.
|
||||
|
||||
#result = q.enqueue(task, task_id, job_timeout=3600)
|
||||
|
||||
http = urllib3.PoolManager()
|
||||
|
||||
try:
|
||||
|
||||
#@app.route('/exec/<api_key>/<int:task_id>')
|
||||
|
||||
r = http.request('GET', 'http://127.0.0.1:1337/exec/{}/{}'.format(config_task.api_key, task_id))
|
||||
|
||||
#print('http://127.0.0.1:1337/exec/{}/{}'.format(task_id, pastafari2_api_key))
|
||||
|
||||
if r.status!=200:
|
||||
self.error=True
|
||||
self.txt_error="Cannot access to task server: Error "+str(r.status)
|
||||
return False
|
||||
|
||||
else:
|
||||
resp=json.loads(r.data.decode('utf-8'))
|
||||
|
||||
if resp['error']:
|
||||
self.error=True
|
||||
self.txt_error=resp['message']
|
||||
logtask=LogTask(self.connection)
|
||||
logtask.insert(resp)
|
||||
return False
|
||||
|
||||
except urllib3.exceptions.MaxRetryError:
|
||||
self.error=True
|
||||
self.txt_error='Cannot connect to the task server, check if is up'
|
||||
return False
|
||||
#result = q.enqueue(task, task_id, job_timeout=3600)
|
||||
|
||||
return True
|
||||
|
||||
# Function for send task to task server
|
||||
# Function for send task to task server
|
||||
|
||||
def send_task_to_server(task_id):
|
||||
def send_task_to_server(self):
|
||||
|
||||
http = urllib3.PoolManager()
|
||||
http = urllib3.PoolManager()
|
||||
|
||||
try:
|
||||
|
||||
#@app.route('/exec/<api_key>/<int:task_id>')
|
||||
|
||||
r = http.request('GET', 'http://127.0.0.1:1337/exec/{}/{}'.format(config_task.api_key, self.task_id))
|
||||
|
||||
#print('http://127.0.0.1:1337/exec/{}/{}'.format(task_id, pastafari2_api_key))
|
||||
|
||||
if r.status!=200:
|
||||
self.error=True
|
||||
self.txt_error="Cannot access to task server: Error "+str(r.status)
|
||||
#logtask=LogTask(conn)
|
||||
#logtask.insert({'task_id': task_id, 'progress': 100, 'message': I18n.lang('pastafari', 'error_in_task', 'Error: error in task server, http error: '+r.status), 'error': 1, 'status': 1})
|
||||
|
||||
try:
|
||||
return False
|
||||
|
||||
#@app.route('/exec/<api_key>/<int:task_id>')
|
||||
|
||||
r = http.request('GET', 'http://127.0.0.1:1337/exec/{}/{}'.format(config_task.api_key, task_id))
|
||||
|
||||
#print('http://127.0.0.1:1337/exec/{}/{}'.format(task_id, pastafari2_api_key))
|
||||
|
||||
if r.status!=200:
|
||||
else:
|
||||
resp=json.loads(r.data.decode('utf-8'))
|
||||
|
||||
if resp['error']:
|
||||
self.error=True
|
||||
self.txt_error=resp['message']
|
||||
#logtask=LogTask(conn)
|
||||
#logtask.insert(resp)
|
||||
return False
|
||||
|
||||
except urllib3.exceptions.MaxRetryError:
|
||||
|
||||
self.error=True
|
||||
self.txt_error="Cannot access to task server: Error "+str(r.status)
|
||||
self.txt_error='Cannot connect to the task server, check if is up'
|
||||
print('Cannot connect to task server...')
|
||||
#logtask=LogTask(conn)
|
||||
#logtask.insert({'task_id': task_id, 'progress': 100, 'message': I18n.lang('pastafari', 'error_cannot_connect_to_task', 'Cannot connect to the task server, check if is up'), 'error': 1, 'status': 1})
|
||||
return False
|
||||
|
||||
else:
|
||||
resp=json.loads(r.data.decode('utf-8'))
|
||||
|
||||
if resp['error']:
|
||||
self.error=True
|
||||
self.txt_error=resp['message']
|
||||
logtask=LogTask(self.connection)
|
||||
logtask.insert(resp)
|
||||
return False
|
||||
|
||||
except urllib3.exceptions.MaxRetryError:
|
||||
self.error=True
|
||||
self.txt_error='Cannot connect to the task server, check if is up'
|
||||
return False
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
# Function used in rq worker for exec the ssh task in rq.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue