Ejemplo n.º 1
0
 def checkSchema(k,schema,attribute='',start=None,end=None):
   #print('In reader.Schemas.checkSchema(%s,%s,%s,%s)'%(schema,attribute,start,end))
   schema = k.getSchema(schema)
   if not schema: return False
   f = schema.get('check')
   if not f: 
     v = True
   else:
     try:
       now = time.time()
       start = fun.notNone(start,now-1)
       end = fun.notNone(end,now)
       k.LOCALS.update({'attribute':attribute.lower(),
             'match':clmatch,'clmatch':clmatch,
             'start':start,'end':end,'now':now,
             'reader':schema.get('reader',schema.get('api')),
             'schema':schema.get('schema'),
             'dbname':schema.get('dbname',schema.get('schema','')),
             })
       #print('(%s)%%(%s)'%(f,[t for t in k.LOCALS.items() if t[0] in f]))
       v =fun.evalX(f,k.LOCALS,k.MODULES)
     except:
       traceback.print_exc()
       v =False
   #print('checkSchema(%s): %s'%(schema,v))
   return v
Ejemplo n.º 2
0
 def update_tasks(self):
   while not self.event.isSet():
     self.last_check = time.time()
     self.info('-'*70)
     self.info( 'In WorkerDS::updateTasks ...')
     self._state = (PyTango.DevState.RUNNING)
     for task,commands in self.tasks.items():
       if task not in self.conditions:
         self.warning('\t%s not scheduled!'%task)
         continue
       if not commands[-1].startswith(task) and ' = ' not in commands[-1]:
         commands[-1] = commands[-1].replace('return ','')
         commands[-1] = task+'_result = '+commands[-1]
       try:
         self.worker.get(commands[-1])
         self.dones[task] = time.time()
       except:
         pass
       try:
         self.update_locals(task=task)
         self.info( 'In WorkerDS::updateTasks(%s): %s'%(task,commands))
         if functional.evalX(self.conditions[task],_locals=self.locals()):
           if not self.dones[task]>=self.sends[task]:
             self.warning('In WorkerDS::updateTasks(%s): still running since %s!!!'%(task,fandango.time2str(self.sends[task])))
           else:
             self.info( 'In WorkerDS::updateTasks(%s)'%task)
             map(self.worker.put,commands)
             self.sends[task] = time.time()
       except:
         self.error(traceback.format_exc())
       wait(.1,self.event)
   
     self.info(' ---- Waiting %s seconds ---- '%self.PollingSeconds)
     self._state = PyTango.DevState.ON
     while not self.waiter.isSet() and time.time()<(self.last_check+int(self.PollingSeconds)):
       status = ['Worker DS waiting %s s for next cycle ..'%self.PollingSeconds]
       status.append('Last check was at %s'%fandango.time2str(self.last_check))
       status.append('')
       for task,commands in sorted(self.tasks.items()):
         if not commands[-1].startswith(task) and ' = ' not in commands[-1]:
           commands[-1] = commands[-1].replace('return ','')
           commands[-1] = task+'_result = '+commands[-1]            
         try:
           self.worker.get(commands[-1])
           self.dones[task] = time.time()
         except:
           pass
         if self.dones[task]>self.sends[task]:
           status.append('%s: Finished at %s'%(task,fandango.time2str(self.dones[task])))
         elif self.sends[task]>self.dones[task]:
           status.append('%s: Launched at %s'%(task,fandango.time2str(self.sends[task])))
       self._status = ('\n'.join(status))
       wait(1.,self.waiter)
     self.waiter.clear()
       
   print '#'*80
   print '#'*80
Ejemplo n.º 3
0
    def update_tasks(self):

        self.last_check = time.time()
        self.info('In WorkerDS::updateTasks ...')
        while not self.event.isSet():

            self.info('#' * 80)
            self.info(' ---- Waiting %s seconds ---- ' % self.PollingSeconds)
            self._state = PyTango.DevState.ON
            self.waiter.clear()

            while not self.waiter.isSet() and time.time() < (
                    self.last_check + int(self.PollingSeconds)):
                status = [
                    'Worker DS waiting %s s for next cycle ..' %
                    self.PollingSeconds
                ]
                status.append('Last check was at %s' %
                              fandango.time2str(self.last_check))
                status.append('')
                self.info('Checking %d tasks: %s' %
                          (len(self.tasks), self.tasks.keys()))

                for task, commands in sorted(self.tasks.items()):
                    if not commands[-1].startswith(
                            task) and ' = ' not in commands[-1]:
                        commands[-1] = commands[-1].replace('return ', '')
                        commands[-1] = task + '_result = ' + commands[-1]
                    try:
                        self.worker.get(commands[-1])
                        self.dones[task] = time.time()
                    except:
                        pass
                    if self.dones[task] > self.sends[task]:
                        status.append(
                            '%s: Finished at %s' %
                            (task, fandango.time2str(self.dones[task])))
                    elif self.sends[task] > self.dones[task]:
                        status.append(
                            '%s: Launched at %s' %
                            (task, fandango.time2str(self.sends[task])))
                    wait(.1)

                self._status = ('\n'.join(status))
                wait(1., self.waiter)
            #self.waiter.clear()

            self.info('-' * 70)
            self.last_check = time.time()
            self._state = (PyTango.DevState.RUNNING)
            for task, commands in self.tasks.items():
                if task not in self.conditions:
                    self.warning('\t%s not scheduled!' % task)
                    continue
                if not commands[-1].startswith(
                        task) and ' = ' not in commands[-1]:
                    commands[-1] = commands[-1].replace('return ', '')
                    commands[-1] = task + '_result = ' + commands[-1]
                try:
                    self.worker.get(commands[-1])
                    self.dones[task] = time.time()
                except:
                    pass
                try:
                    self.update_locals(task=task)
                    self.info('In WorkerDS::updateTasks(%s): %s' %
                              (task, commands))
                    if functional.evalX(self.conditions[task],
                                        _locals=self.locals()):
                        if not self.dones[task] >= self.sends[task]:
                            self.warning(
                                'In WorkerDS::updateTasks(%s): still running since %s!!!'
                                % (task, fandango.time2str(self.sends[task])))
                        else:
                            self.info('In WorkerDS::updateTasks(%s)' % task)
                            map(self.worker.put, commands)
                            self.sends[task] = time.time()
                except:
                    self.error(traceback.format_exc())
                wait(.1, self.event)

            wait(.1)