本文整理汇总了Python中stackone.model.DBSession.merge方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.merge方法的具体用法?Python DBSession.merge怎么用?Python DBSession.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stackone.model.DBSession
的用法示例。
在下文中一共展示了DBSession.merge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_entity_task_entries
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import merge [as 别名]
def make_entity_task_entries(self, task_id, entity_ids):
ent_tasks = []
#add 0902
WRK_LOGGER.debug('in make_entity_task_entries task_id : ' + str(task_id) + ' :entity_ids :' + str(entity_ids))
for ent_id in entity_ids:
try:
ent_task = EntityTasks(self.worker, to_unicode(task_id), ent_id, False, datetime.now())
ent_tasks.append(ent_task)
except Exception as e:
traceback.print_exc()
self.update_execution_context()
for ent_task in ent_tasks:
DBSession.merge(ent_task)
transaction.commit()
#add 0902
WRK_LOGGER.debug('in make_entity_task_entries committed task_id : ' + str(task_id) + ' :entity_ids :' + str(entity_ids))
示例2: wait_for_workers_to_finish
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import merge [as 别名]
def wait_for_workers_to_finish(self, task_ids):
WRK_LOGGER.debug('wait_for_workers_to_finish for ' + self.worker + ' max_worker_wait_time: ' + str(self.max_worker_wait_time))
task_completed = False
self.wait_start_time = datetime.now()
while task_completed == False:
time.sleep(5)
completed_tasks = self.check_tasks_completed(task_ids)
WRK_LOGGER.debug('wait_for_workers_to_finish for ' + self.worker + ' completed_tasks :' + str(completed_tasks))
if len(completed_tasks) > 0:
task_completed = True
for task in completed_tasks:
self.worker_ids.remove(task['task_id'])
WRK_LOGGER.debug('child task completed, update EntityTasks ' + self.worker + ' completed_tasks :' + str(task['task_id']))
ets = DBSession.query(EntityTasks).filter(EntityTasks.worker_id == to_unicode(task['task_id'])).all()
for et in ets:
et.worker_id = None
et.finished = True
et.end_time = datetime.now()
DBSession.merge(et)
transaction.commit()
WRK_LOGGER.debug('child tasks completed, updated EntityTasks ' + self.worker)
wait_time_sec = (datetime.now() - self.wait_start_time).seconds
WRK_LOGGER.debug('No completed child tasks for ' + self.worker + '. waiting for ' + str(wait_time_sec))
if wait_time_sec > self.max_worker_wait_time:
task_service = self.svc_central.get_service(self.task_service_id)
past_time = self.start_time - timedelta(minutes=1)
for task_id in task_ids:
task_obj = task_service.get_running_task_obj(task_id)
if task_obj:
(hung,completed,pending) = task_obj.get_running_status()
WRK_LOGGER.debug('HUNG STATUS for ' + self.worker + ':' + str(hung) + ':' + str(task_id) + ':' + str(completed) + ':' + str(pending))
if hung:
task_completed = True
self.worker_ids.remove(task_id)
WRK_LOGGER.debug('Hung task. Cleanup EntityTask for ' + self.worker + '. task id : ' + str(task_id))
DBSession.query(EntityTasks).filter(EntityTasks.worker == self.worker).filter(EntityTasks.entity_id.in_(completed)).update(dict(worker_id=None, finished=True, end_time=datetime.now()))
DBSession.query(EntityTasks).filter(EntityTasks.worker == self.worker).filter(EntityTasks.entity_id.in_(pending)).update(dict(worker_id=None, finished=True, start_time=past_time))
transaction.commit()
WRK_LOGGER.debug('Hung task. Cleaned up EntityTask for ' + self.worker + '. task id : ' + str(task_id))
示例3: save_dwm_details
# 需要导入模块: from stackone.model import DBSession [as 别名]
# 或者: from stackone.model.DBSession import merge [as 别名]
def save_dwm_details(self, auth, group_id, policy_object, enabled, offset):
try:
self.tc = TaskCreator()
self.utcoffset = timedelta(milliseconds=long(offset))
group = self.get_group(auth, group_id)
if enabled == 'true':
dwm_list = DBSession.query(DWM).filter(DWM.sp_id == group_id).all()
task_ids = []
interval_task_ids = []
dwmelems = {}
for dwmelem in dwm_list:
interval_task_ids.append(dwmelem.interval_task_id)
if dwmelem.calendar_task_ids:
task_ids.extend(dwmelem.calendar_task_ids)
dwmelem.enabled = False
dwmelems[dwmelem.policy] = dwmelem
if task_ids:
self.tc.delete_task(task_ids)
policy_obj = json.loads(policy_object)
policies = policy_obj['policy_object']['policies']
freq = 5
dwms = []
schedules = []
for policy in policies:
dwmelem = dwmelems.get(policy['policy_name'])
if dwmelem != None:
dwmelem.enabled = True
(dwm, policy_schedules) = self.save_dwm_policy(auth, group_id, policy['threshold'], policy['frequency'], policy['data_period'], policy['upper_threshold'], policy['policy_name'], policy['schedule_object'])
freq = policy['frequency']
dwms.append(dwm)
schedules.extend(policy_schedules)
sp_dwm = SPDWMPolicy(group_id, None)
DBSession.merge(sp_dwm)
if interval_task_ids:
self.tc.delete_task(interval_task_ids)
interval_task_id = self.tc.dwm_task(auth, group_id, freq)
for d in dwms:
d.interval_task_id = interval_task_id
DBSession.add(d)
group.dwm_enabled = True
DBSession.add(group)
transaction.commit()
DBSession.add_all(schedules)
transaction.commit()
DBSession.query(DWM).filter(DWM.sp_id == group_id).update(dict(interval_task_id=interval_task_id))
pol = DWM.find_current_policy(group_id)
if pol and pol.is_enabled():
sp_dwm = SPDWMPolicy.set_sp_current_policy(group_id, pol.policy, SPDWMPolicy.ON)
return True
result = self.delete_dwm_tasks(auth, group_id)
DBSession.query(DWM).filter(DWM.sp_id == group_id).update(dict(interval_task_id=None, calendar_task_ids=None))
group.dwm_enabled = False
DBSession.add(group)
sp_dwm = SPDWMPolicy(group_id, None)
DBSession.merge(sp_dwm)
return result
except Exception as ex:
traceback.print_exc()
raise ex