当前位置: 首页>>代码示例>>Python>>正文


Python Schedule.add_entry_cid方法代码示例

本文整理汇总了Python中schedule.Schedule.add_entry_cid方法的典型用法代码示例。如果您正苦于以下问题:Python Schedule.add_entry_cid方法的具体用法?Python Schedule.add_entry_cid怎么用?Python Schedule.add_entry_cid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schedule.Schedule的用法示例。


在下文中一共展示了Schedule.add_entry_cid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Provisioner

# 需要导入模块: from schedule import Schedule [as 别名]
# 或者: from schedule.Schedule import add_entry_cid [as 别名]

#.........这里部分代码省略.........
    
    def sync_machines(self):
        slots_addrs = condor_slots()
        running_machines = [m for m in self.machines if m.status == MachineStatus.running]
        allocating_machines = [m for m in self.machines if m.status == MachineStatus.allocating]
        #allocating_machines.sort(key=lambda x: self.schedule.entries_host[x][0].start())
        i = 0
        for (slot,addr) in slots_addrs:
            if slot not in [m.condor_slot for m in running_machines]:
                allocated_machine = None
                if not self.local:
                    allocated_machine = next((m for m in allocating_machines if m.priv_addr == addr), None)
                elif len(allocating_machines[i:]) > 0:
                    # update machine
                    allocated_machine = allocating_machines[i]
                
                if allocated_machine:
                    allocated_machine.status = MachineStatus.running
                    allocated_machine.condor_slot = slot
                    
                    # update entry
                    boot_entry = self.schedule.entries_host[allocated_machine][0]
                    boot_entry.log[LogKey.real_end] = self.timestamp
                    boot_entry.status = EntryStatus.completed
                
                    i += 1
                    print "++Machine", allocated_machine.condor_slot
                else:
                    if next((e for e in self.schedule.entries if e.host.priv_addr == addr and e.status != EntryStatus.completed), None):
                        print "ERROR: slot not found", slot, addr, 'nr', len(running_machines), 'na', len(allocating_machines)
                

    
    def _handle_log_events(self):
        jobs_terminated = False
        log_entries = self.logwatcher.nexts()
        
        for le in log_entries:
            if le.id in self.schedule.entries_cid:
                sched_entry = self.schedule.entries_cid[le.id]
            else:
                sched_entry = next((e for e in self.schedule.entries if e.job.dag_job_id == le.name and e.job.wf_id == le.wf_id), None)
                if sched_entry:
                    sched_entry.condor_id = le.id
                    self.schedule.add_entry_cid(sched_entry)
            if sched_entry:
                sched_entry.log[le.event] = le.timestamp
                
                if le.event == LogKey.execute:
                    sched_entry.status = EntryStatus.executing
            
                elif le.event == LogKey.job_terminated:
                    sched_entry.status = EntryStatus.completed 
                    sched_entry.log[LogKey.real_end] = self.timestamp
                    print "--Job", le.id, sched_entry.job.dag_job_id, sched_entry.host.condor_slot
                    jobs_terminated = True
            else:
                print 'could not find sched_entry for:', le.id
        return jobs_terminated
                
    def _handle_ready_jobs(self):    
        need_condor_resched = False
        idle_cjobs = condor_idle() # idle jobs

        for cjob in idle_cjobs:
            condor_id, wf_id, dag_job_id = cjob.split()
            if condor_id in self.schedule.entries_cid:
                sched_entry = self.schedule.entries_cid[condor_id]
            else:
                sched_entry = next((e for e in self.schedule.entries \
                                    if e.job.dag_job_id == dag_job_id \
                                    and e.job.wf_id == wf_id ), None)
                if sched_entry:
                    sched_entry.condor_id = condor_id
                    self.schedule.add_entry_cid(sched_entry)

            if sched_entry and sched_entry.status == EntryStatus.scheduled \
                    and sched_entry.host.status == MachineStatus.running:
                sched_entry.status = EntryStatus.executing
                sched_entry.log[LogKey.real_start] = self.timestamp
                print "++Job", condor_id, dag_job_id, sched_entry.host.condor_slot
                condor_qedit(condor_id, wf_id, dag_job_id, sched_entry.host.condor_slot)
                need_condor_resched = True

        if need_condor_resched:
            condor_reschedule()

    def update_jobs(self):
        
        # handle log events and check if any job terminated
        self.jobs_terminated = self._handle_log_events() or self.jobs_terminated
        
        # need to update schedule (?)
        if self.last_resched and self.jobs_terminated and \
        ((self.timestamp - self.last_resched).seconds > SCHED_TIMEOUT):
            self.update_schedule()
            self.jobs_terminated = False
        
        # handle jobs that are ready to execute
        self._handle_ready_jobs()
开发者ID:rika,项目名称:dynamic-provisioning,代码行数:104,代码来源:provisioner.py


注:本文中的schedule.Schedule.add_entry_cid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。