Merge branch 'processing' into tasklist

pull/40/head
Piero Toffanin 2016-10-26 18:25:04 -04:00
commit 113f0142bd
2 zmienionych plików z 14 dodań i 13 usunięć

Wyświetl plik

@ -9,7 +9,7 @@ from django.db.models import Q
import random
logger = logging.getLogger('app.logger')
scheduler = None
scheduler = BackgroundScheduler()
def job(func):
"""
@ -17,7 +17,8 @@ def job(func):
so that we can call update_nodes_info(background=True) from the outside
"""
def wrapper(*args,**kwargs):
if (kwargs.get('background', False)):
background = kwargs.get('background', False)
if background:
t = Thread(target=func)
t.start()
return t
@ -59,16 +60,13 @@ def process_pending_tasks():
if tasks.count() > 0:
pool = ThreadPool(tasks.count())
pool.map(process, tasks)
pool.map(process, tasks, chunksize=1)
pool.close()
pool.join()
def setup():
global scheduler
logger.info("Starting background scheduler...")
try:
scheduler = BackgroundScheduler()
scheduler.start()
scheduler.add_job(update_nodes_info, 'interval', seconds=30)
scheduler.add_job(process_pending_tasks, 'interval', seconds=5)
@ -76,9 +74,8 @@ def setup():
logger.warn("Scheduler already running (this is OK while testing)")
def teardown():
if scheduler != None:
logger.info("Stopping scheduler...")
try:
scheduler.shutdown()
except SchedulerNotRunningError:
logger.warn("Scheduler not running")
logger.info("Stopping scheduler...")
try:
scheduler.shutdown()
except SchedulerNotRunningError:
logger.warn("Scheduler not running")

Wyświetl plik

@ -6,6 +6,7 @@ import requests
import mimetypes
import json
import os
from urlparse import urlunparse
class ApiClient:
def __init__(self, host, port):
@ -13,7 +14,10 @@ class ApiClient:
self.port = port
def url(self, url):
return "http://{}:{}{}".format(self.host, self.port, url)
netloc = self.host if self.port == 80 else "{}:{}".format(self.host, self.port)
# TODO: https support
return urlunparse(('http', netloc, url, '', '', ''))
def info(self):
return requests.get(self.url('/info')).json()