def send_worker_command(request): if request.POST: command = request.POST['command'] worker_id = request.POST['worker_id'] Master.send_master(command, worker_id) return HttpResponse('Command sent to worker') return HttpResponse('Missing command and worker to send, use POST')
def session_detail_start(request): if request.POST: session_detail_id = request.POST['session_detail_id'] worker_id = request.POST['worker_id'] Master.start_work(worker_id, session_detail_id) return HttpResponse('Session detail started') return HttpResponse('Missing session detail to start, use POST')
def send_session_detail_command(request): if request.POST: command = request.POST['command'] session_detail_id = request.POST['session_detail_id'] session_detail = SessionDetail.objects.get(pk=int(session_detail_id)) if session_detail.assigned_worker is None: return HttpResponse('Session detail has no assigned worker') worker_id = str(session_detail.assigned_worker.id) Master.send_master(command, worker_id) return HttpResponse('Command sent to worker') return HttpResponse('Missing command and worker to send, use POST')
def ping_master(request): stamp = timezone.now() Master.send_ping() pong = False count = 0 while not pong and count < 5: found = Message.objects.filter(type=log.LOG_TYPE_TEXT[log.INFO], timestamp__gt=stamp, text=MessagePong) if len(found) > 0: pong = True else: time.sleep(1) count += 1 if pong: return HttpResponse(MessagePong) return HttpResponse('No reply from master')
def handle(self, *args, **options): from django.conf import settings translation.activate(settings.LANGUAGE_CODE) if len(options) > 0: config_file = options['config'] else: config_file = defaults.DEFAULT_CONFIG try: self.stdout.write('Starting Twisted Brew (config:{0})'.format(config_file)) master = None config = coreutils.parse_config(config_file) if config.master is not None: master = Master(config.communication, config.master) coreutils.start_workers(config) if master is not None: master.info() master.start() else: log.set_log_receiver(log.LOG_RECEIVER_STD) except Exception as e: raise CommandError('Could not start Twisted Brew: {0}'.format(e.__class__.__name__)) self.stdout.write('Successfully started Twisted Brew')
def workers_info(request): Master.send_master("info") return HttpResponse('All workers asked to reregister')
def send_master_command(request): if request.POST: command = request.POST['command'] Master.send_master(command) return HttpResponse('Command sent to master') return HttpResponse('Missing command to send, use POST')