本文整理汇总了Python中google3.enterprise.legacy.util.E.exec_locked方法的典型用法代码示例。如果您正苦于以下问题:Python E.exec_locked方法的具体用法?Python E.exec_locked怎么用?Python E.exec_locked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google3.enterprise.legacy.util.E
的用法示例。
在下文中一共展示了E.exec_locked方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import exec_locked [as 别名]
def execute(self, argv):
"""
This executes the service given the command line arguments.
The first two argument are 'ent_home' and 'task' than is it's the
children job to parse the extra args if it wants by overriding parse_args
"""
# Args parsing
if len(argv) < 3:
sys.exit(self.usage())
# Get the first two arguments and intitialize
self.init_service(argv[1])
self.task = string.strip(argv[2])
# Get the other arguments and call the parsing function
flags_argv = [argv[0]]
flags_argv.extend(argv[3:])
self.parse_args(flags_argv)
# Extra checks
if not self.service_to_be_up():
sys.exit('%s not active' % self.service_name)
# check if the node is enabled
testver = install_utilities.is_test(self.version)
if core_utils.AmIDisabled(self.version, testver):
logging.error('I am disabled.')
sys.exit(-1)
if (self.performs_only_on_master and
self.task not in ("activate", "deactivate")):
if not self.local_machine_is_master:
logging.error('I am not the master')
self.nop()
sys.exit(0)
if not self.task:
sys.exit(self.usage())
# Execute the operations behind a lock
lockfile = "%s/%s_service_lock_%s" % (self.tmpdir,
self.service_name,
self.version)
pidfile = "%s/%s_service_pid_%s" % (self.tmpdir,
self.service_name,
self.version)
# Execute the task: unlocked on activate/deactivate /
# locked else
if self.task in ["activate", "deactivate"]:
do_task(self, self.task)
else:
if self.check_previous_cron_job:
# kill previous cron job if lockfile timestamp is too old
valid_lock_duration = self.secs_to_kill_previous_job
# for "stop" and "restart" task, do it immediately
if self.task in ["stop", "restart"]:
valid_lock_duration = 0
E.exec_locked(lockfile, 1, do_task, (self, self.task,), {},
valid_lock_duration, pidfile)
else:
# Lock will time out after 60 rounds of 10 seconds
E.exec_locked(lockfile, 60, do_task, (self, self.task,))