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


Python Backend.post_job方法代码示例

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


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

示例1: Scheduler

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import post_job [as 别名]
class Scheduler(object):

	# structure = {
	# 	'type': IS(*TYPE.values_both_types()),
	# 	'state': IS(*STATE.values_both_types()),
	# 	'jobInfo': dict,
	# 		accountId, bundleId, storeCountry, appType{appstore,cydia}
	# 	'worker': Worker,
	# 	'device': Device,
	# 	'date_added': float
	# }

	@classmethod
	def _default_runjob(cls):
		return {
			'type':'run_app',
			'state':'pending',
			'jobInfo': {
				'appType':'AppStoreApp'
			},
		}


	def __init__(self, backendUrl):
		self.backend = Backend(backendUrl)

	def schedule_job(self, jobDict):
		job = Scheduler._default_runjob()
		job = dict_merge(job, jobDict)
		jobId = self.backend.post_job(job)
		return jobId


	def schedule_bundleId(self, bundleId, worker=None, device=None, account=None, country=None, executionStrategy=None):
		jobDict = {
			'jobInfo': {
				'bundleId':bundleId
			}
		}
		if worker:
			jobDict['worker'] = worker
		if device:
			jobDict['device'] = device
		if account:
			jobDict['jobInfo']['accountId'] = account
		if country:
			jobDict['jobInfo']['storeCountry'] = country
		if executionStrategy:
			jobDict['jobInfo']['executionStrategy'] = executionStrategy
		return self.schedule_job(jobDict)


	def schedule_appId(self, appId, account=None, country=None, executionStrategy=None):
		url = 'http://itunes.apple.com/lookup?id=%s' % appId
		r = requests.get(url)
		if r.status_code != 200:
			logging.error("Requests to %s failed: %s", (url, r.text))
			return False

		resDict = json.loads(r.text)
		results = resDict['results']
		if len(results) != 1:
			logger.error("No app with id %s found", (appId))
			return False
		return self.schedule_bundleId(results[0]['bundleId'], account=account, country=country, executionStrategy=None)



	def schedule_itunes(self, url, account=None, country=None, executionStrategy=None):
		logger.info('Adding apps from iTunes (%s)' % url)
		r = requests.get(url)
		if r.status_code != 200:
			logging.error("Requests to %s failed: %s", (url, r.text))
			return False

		resDict = json.loads(r.text)
		entries = resDict['feed']['entry']
		result = True
		for entry in entries:
			if not self.schedule_bundleId(entry['id']['attributes']['im:bundleId'], account=account, country=country, executionStrategy=None):
				result = False
		return result
开发者ID:DiOS-Analysis,项目名称:Worker,代码行数:84,代码来源:scheduler.py

示例2: Scheduler

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import post_job [as 别名]
class Scheduler(object):

	# structure = {
	# 	'type': IS(*TYPE.values_both_types()),
	# 	'state': IS(*STATE.values_both_types()),
	# 	'jobInfo': dict,
	# 		accountId, bundleId, storeCountry, appType{appstore,cydia}
	# 	'worker': Worker,
	# 	'device': Device,
	# 	'date_added': float
	# }

	@classmethod
	def _default_runjob(cls):
		return {
			'type':'run_app',
			'state':'pending',
			'jobInfo': {
				'appType':'AppStoreApp'
			},
		}

	@classmethod
	def _default_dioscopejob(cls):
		return {
			'type':'dioscope',
			'state':'pending',
			'jobInfo': {
				'appType':'AppStoreApp'
			}
		}

	def __init__(self, backendUrl):
		self.backend = Backend(backendUrl)

	def schedule_job(self, jobDict, type='run'):
		if type == 'dioscope':
			job = Scheduler._default_dioscopejob()
		else:
			job = Scheduler._default_runjob()
		job = dict_merge(job, jobDict)
		jobId = self.backend.post_job(job)
		return jobId


	def schedule_bundleId(self, bundleId, worker=None, device=None, account=None, country=None, executionStrategy=None, type='run'):
		jobDict = {
			'jobInfo': {
				'bundleId':bundleId
			}
		}
		if worker:
			jobDict['worker'] = worker
		if device:
			jobDict['device'] = device
		if account:
			jobDict['jobInfo']['accountId'] = account
		if country:
			jobDict['jobInfo']['storeCountry'] = country
		if executionStrategy:
			jobDict['jobInfo']['executionStrategy'] = executionStrategy
		return self.schedule_job(jobDict, type)


	def schedule_appId(self, appId, account=None, country=None, executionStrategy=None):
		url = 'http://itunes.apple.com/lookup?id=%s' % appId
		r = requests.get(url)
		if r.status_code != 200:
			logging.error("Requests to %s failed: %s", (url, r.text))
			return False

		resDict = json.loads(r.text)
		results = resDict['results']
		if len(results) != 1:
			logger.error("No app with id %s found", (appId))
			return False
		return self.schedule_bundleId(results[0]['bundleId'], account=account, country=country, executionStrategy=None)



	def schedule_itunes(self, url, account=None, country=None, executionStrategy=None):
		logger.info('Adding apps from iTunes (%s)' % url)
		r = requests.get(url)
		if r.status_code != 200:
			logging.error("Requests to %s failed: %s", (url, r.text))
			return False

		resDict = json.loads(r.text)
		entries = resDict['feed']['entry']
		result = True
		for entry in entries:
			if not self.schedule_bundleId(entry['id']['attributes']['im:bundleId'], account=account, country=country, executionStrategy=None):
				result = False
		return result
	
	def schedule_dioscope_new(self, host, index, account=None, country=None, executionStrategy=None):
		es = Elasticsearch([host])
		result = es.search(index=index, doc_type="app", fields="bundleId.untouched,currentVersionReleaseDate,version", size=1000)
		apps = result['hits']['hits']
		count = 0
#.........这里部分代码省略.........
开发者ID:L45eMy,项目名称:Worker,代码行数:103,代码来源:scheduler.py


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