Fixes in tasks
This commit is contained in:
parent
17b021fa33
commit
60786dd6c4
1 changed files with 31 additions and 2 deletions
|
|
@ -143,7 +143,8 @@ class Task(WebModel):
|
||||||
return False
|
return False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.send_task(task_id, yes_parent, where_sql_server)
|
#return self.send_task(task_id, yes_parent, where_sql_server)
|
||||||
|
return self.send_task_to_server(task_id, yes_parent, where_sql_server)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
q = Queue(connection=Redis(host=redis_host, port=redis_port, password=redis_password))
|
q = Queue(connection=Redis(host=redis_host, port=redis_port, password=redis_password))
|
||||||
|
|
@ -243,12 +244,40 @@ class Task(WebModel):
|
||||||
|
|
||||||
# Function for send task to task server if not using rq worker
|
# Function for send task to task server if not using rq worker
|
||||||
|
|
||||||
def send_task_to_server(self):
|
def send_task_to_server(self, task_id, yes_parent=False, where_sql_server=''):
|
||||||
|
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
if yes_parent:
|
||||||
|
arr_task=self.select_a_row(task_id)
|
||||||
|
#If where sql, send multiple tasks.
|
||||||
|
sql_insert_values=[]
|
||||||
|
sql_insert='insert into task (`name_task`, `description_task`, `url_return`, `server`, `hostname`, `data`, `user`, `password`, `path`, `ssh_key_priv`, `ssh_key_password`, `parent_id`, `ssh_port`) VALUES '
|
||||||
|
|
||||||
|
with self.query('select id, hostname, ip, ssh_port from serverdbtask '+where_sql_server) as cursor:
|
||||||
|
|
||||||
|
for row in cursor:
|
||||||
|
arr_task['server']=row['ip'] #row['hostname']
|
||||||
|
arr_task['ssh_port']=row['ssh_port'] #row['hostname']
|
||||||
|
sql_insert_values.append("('"+arr_task['name_task']+"', '"+arr_task['description_task']+"', '"+arr_task['url_return']+"', '"+arr_task['server']+"', '"+row['hostname']+"', '"+arr_task['data']+"', '"+arr_task['user']+"', '"+arr_task['password']+"', '"+arr_task['path']+"', '"+arr_task['ssh_key_priv']+"', '"+arr_task['ssh_key_password']+"', '"+str(task_id)+"', '"+str(arr_task['ssh_port'])+"')")
|
||||||
|
|
||||||
|
#self.insert({'name_task': name_task,'description_task': description_task, 'url_return': url, 'server': server, 'where_sql_server': where_sql_server, 'data': data , 'user': user, 'password': password, 'path': path, 'where_sql_server' : where_sql_server, 'ssh_key_priv': ssh_key_priv, 'ssh_key_password': ssh_key_password})
|
||||||
|
pass
|
||||||
|
|
||||||
|
final_sql=sql_insert+", ".join(sql_insert_values)
|
||||||
|
|
||||||
|
self.query(final_sql)
|
||||||
|
|
||||||
|
"""
|
||||||
|
with self.query('select id from task WHERE parent_id=%s', [task_id]) as cursor:
|
||||||
|
|
||||||
|
for row in cursor:
|
||||||
|
#print(row)
|
||||||
|
result = q.enqueue(task, row['id'], job_timeout=3600)
|
||||||
|
"""
|
||||||
|
|
||||||
#@app.route('/exec/<api_key>/<int:task_id>')
|
#@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))
|
r = http.request('GET', 'http://127.0.0.1:1337/exec/{}/{}'.format(config_task.api_key, self.task_id))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue