def tests(): clusters = db.get_cluster_names() cluster_scheduled_tests = {} cluster_in_progress_tests = {} for c in clusters: scheduled_tests = db.get_scheduled_tests(c) if len(scheduled_tests) > 0: cluster_scheduled_tests[c] = scheduled_tests in_progress_tests = db.get_in_progress_tests(c) if len(in_progress_tests) > 0: cluster_in_progress_tests[c] = in_progress_tests completed_tests = db.get_completed_tests() return render_template('tests.jinja2.html', clusters=clusters, cluster_scheduled_tests=cluster_scheduled_tests, cluster_in_progress_tests=cluster_in_progress_tests, completed_tests=completed_tests)
def get_work(command): # Mark any existing in_process jobs for this cluster as # failed. If the cluster is asking for new work, then these # got dropped on the floor: for test in db.get_in_progress_tests(context['cluster']): db.update_test_status(test['test_id'], 'failed') # Find the next test scheduled for the client's cluster: tests = db.get_scheduled_tests(context['cluster'], limit=1) if len(tests) > 0: test_id = tests[0]['test_id'] else: # No tests are currently scheduled. # Register a zmq listener of notifications of incoming tests, with a timeout. # When we see any test scheduled notification for our cluster, redo the query. # If timeout reached, redo the query anyway in case we missed the notification. def setup_zmq(): zmq_context = zmq.Context() zmq_socket = zmq_context.socket(zmq.SUB) zmq_socket.connect('tcp://127.0.0.1:5557') zmq_socket.setsockopt_string( zmq.SUBSCRIBE, unicode('scheduled {cluster} '.format( cluster=context['cluster']))) zmq_socket.setsockopt(zmq.RCVTIMEO, 15000) return zmq_socket zmq_socket = setup_zmq() while True: try: cluster, test_id = zmq_socket.recv_string().split() except zmq.error.Again: pass except zmq.error.ZMQError, e: if e.errno == zmq.POLLERR: log.error(e) # Interrupted zmq socket code, reinitialize: # I get this when I resize my terminal.. WTF? zmq_socket = setup_zmq() finally: tests = db.get_scheduled_tests(context['cluster'], limit=1)
def get_work(command): # Mark any existing in_process jobs for this cluster as # failed. If the cluster is asking for new work, then these # got dropped on the floor: for test in db.get_in_progress_tests(context['cluster']): db.update_test_status(test['test_id'], 'failed') # Find the next test scheduled for the client's cluster: tests = db.get_scheduled_tests(context['cluster'], limit=1) if len(tests) > 0: test_id = tests[0]['test_id'] else: # No tests are currently scheduled. # Register a zmq listener of notifications of incoming tests, with a timeout. # When we see any test scheduled notification for our cluster, redo the query. # If timeout reached, redo the query anyway in case we missed the notification. def setup_zmq(): zmq_context = zmq.Context() zmq_socket = zmq_context.socket(zmq.SUB) zmq_socket.connect('tcp://127.0.0.1:5557') zmq_socket.setsockopt_string( zmq.SUBSCRIBE, unicode('scheduled {cluster} '.format(cluster=context['cluster']))) zmq_socket.setsockopt(zmq.RCVTIMEO, 15000) return zmq_socket zmq_socket = setup_zmq() while True: try: cluster, test_id = zmq_socket.recv_string().split() except zmq.error.Again: pass except zmq.error.ZMQError, e: if e.errno == zmq.POLLERR: log.error(e) # Interrupted zmq socket code, reinitialize: # I get this when I resize my terminal.. WTF? zmq_socket = setup_zmq() finally: tests = db.get_scheduled_tests(context['cluster'], limit=1)