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_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 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')
#!/usr/bin python import django.conf import sys import twisted_brew.settings django.conf.settings.configure() django.conf.settings.DATABASES = twisted_brew.settings.DATABASES django.conf.settings.INSTALLED_APPS = twisted_brew.settings.INSTALLED_APPS from core.utils import coreutils import core.defaults as defaults from core.master import Master configfile = defaults.DEFAULT_CONFIG if len(sys.argv) > 1: configfile = sys.argv[1] print('Starting Twisted Brew (config:{0})'.format(configfile)) master = None config = coreutils.parse_config(configfile) 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()
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')
lex_file = '../data/lexiques/ultimate_556105.txt' lex_file = args.lex_file word_length = 10 word_length = args.word_size be_master = args.be_master master_host = '127.0.0.1' master_host = args.master_host master_port = 6969 master_port = args.master_port l = Lexique(lex_file, word_length) word_statistics = WordStatistics(l) if be_master: runner = Master(host = master_host, port = master_port) else: runner = Worker(master_host, port = master_port) runner.run(l, word_statistics)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @time : 2019/5/4 20:42 @file : submit.py @author : zhipeng.zhao @contact : [email protected] """ import os import sys bin_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.dirname(bin_dir)) from conf import settings settings.BIN_DIR = os.path.abspath(os.path.dirname(__file__)) from core.params_parser import ParamsParser from core.master import Master if __name__ == '__main__': params_obj = ParamsParser() if params_obj.is_ready: maser = Master(params_obj) maser.run()
def run(config, cli): master = Master(cli) master.init(config) master.run()