def addEntry(self, label, **kwds): t = time.time() kwds["_master_uuid"] = self.uuid msg = repr([t, label, kwds]) import MSGWrap MSGWrap.journalEntry([t, label, kwds]) self.f.write(msg + "\n") self.f.flush()
def run(self): import MSGWrap from diane.config import log_configuration log_configuration(title='initial configuration') msg_data = { '_worker_uuid' : self.uuid } try: self.registerToMaster() master = StandingCall(self.master, config.HEARTBEAT_DELAY, should_stop = self.should_stop) app_boot,app_init = master.get_init_data(self.uuid) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'get_init_data',self.uuid) _boot = streamer.loads(app_boot) msg_data['_master_uuid'] = _boot.master_uuid msg_data['_runid'] = _boot.runid import os msg_data['ganga_job_uuid'] = self.ganga_job_uuid # FIXME: if worker restart enabled, save diane.config.__all_configs and restore it after run has finished MSGWrap.sendStatus('_worker_create_application_proxy_start', msg_data) self.application = create_application_proxy(app_boot,app_init,agent=self) MSGWrap.sendStatus('_worker_create_application_proxy_finish', msg_data) self.program.registerAtExitHandler(self.finalize_application) MSGWrap.sendStatus('_worker_initialize_start', msg_data) app_init_output = self.application.initialize(app_init) MSGWrap.sendStatus('_worker_initialize_finish', msg_data) # config may have been updated and the value of config.HEARTBEAT_DELAY may have changed -> need to create the object again # FIXME: use a REFERENCE to config.HEARTBEAT_DELAY master = StandingCall(self.master, config.HEARTBEAT_DELAY, should_stop = self.should_stop) master.put_init_result(self.uuid,app_init_output,0) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'put_init_result',self.uuid,app_init_output,0) while not self.should_stop(): time.sleep(config.PULL_REQUEST_DELAY) # PENDING: this parameter should be dynamically controlled by the master tid,task_data = master.get_task_data(self.uuid) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'get_task_data',self.uuid) try: msg_data['tid'] = tid MSGWrap.sendStatus('_worker_do_work_start', msg_data) task_result = self.application.do_work(task_data) MSGWrap.sendStatus('_worker_do_work_finish', msg_data) error = 0 except diane.application.ApplicationFailure,x: # recoverable problem task_result = streamer.dumps(x) error = 1 #FIXME: reporting failure is not yet well-defined master.put_task_result(self.uuid,tid,task_result,error) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'put_task_result',self.uuid,tid,task_result,error) except diane.application.ApplicationFailure,x: # recoverable problem but raised by the application init pass