本文整理汇总了Python中models.Job.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Job.get_by_id方法的具体用法?Python Job.get_by_id怎么用?Python Job.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Job
的用法示例。
在下文中一共展示了Job.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reschedule
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def reschedule(id):
job = Job.get_by_id(int(id))
if job is not None and job.lead is not None:
post_data = get_post_data()
if 'schedule_options' in post_data:
options = []
for o in post_data['schedule_options']:
options.append(datetime.datetime.strptime(o, DATE_FORMAT))
# updates the lead schedule options
lead = job.lead.get()
lead.schedule_options = options
lead.put()
# mark the job as reopened and clean scheduled_date
job.status = 'REOPENED'
job.scheduled_date = None
job.put()
# reschedule the job in townflix
tf_reschedule_job(job.tf_job_id, job.key.id(), options)
# send a message to property owner telling him that his job has been rescheduled
_enqueue_job_reschedule_message(job)
return jsonify(data=job.to_json()), 201
else:
return jsonify(data={}), 404
示例2: create_at_townflix
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def create_at_townflix():
pprint.pprint('###### BACKGROUND PROCESSING!')
# find a job by id
job_id = request.form['job_id']
job = Job.get_by_id(int(job_id))
# if job is found
if job is not None:
# creates a job in townflix
tf_job_id = _create_job_at_townflix(job)
# updates the job with the id returned by townflix
if tf_job_id is not None:
job.tf_job_id = tf_job_id
job.put()
lead = job.lead.get()
lead.status = 'CONVERTED'
lead.put()
# pprint.pprint('/jobs/create_at_townflix')
# pprint.pprint('=== LEAD UPDATED')
# pprint.pprint('Lead Id: ' % lead.key.id())
# pprint.pprint('Lead Status: ' % lead.status)
return '', 200
return '', 500
示例3: cancel
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def cancel(id):
job = Job.get_by_id(int(id))
if job.status == 'CREATED':
return _cancel_created_job(job)
if job.status == 'ASSIGNED':
return _cancel_assigned_job(job, cancelled_by_flixer=True)
示例4: _get_job
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def _get_job(id):
job = Job.get_by_id(int(id))
if job is not None:
return job
else:
abort(404, {'message': 'Job not found'})
示例5: get
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def get(id):
job = Job.get_by_id(int(id))
if job is not None:
return jsonify(data=job.to_json()), 200
else:
return jsonify(data={}), 404
示例6: run
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import get_by_id [as 别名]
def run(self):
"""Function that will upload a new file, slice it if needed,
and delete stl files from the octopi. Should be used whenever
a new job is uploaded to the hub
:returns: boolean of success
"""
id = self.id
log = self.log
job_id = self.job_id
webapi = self.webapi
loc = octopi.local
printer = Printer.get_by_id(id, fresh=True)
ip = printer.ip
port = printer.port
key = printer.key
job = Job.get_by_id(job_id)
log.log("Starting job upload to " + str(id)
+ " for job " + str(job.id))
fpath = job.file.path
job.state("processing")
url = ip + ":" + str(port)
r = octopi.upload_file(url, key, fpath, loc)
if r == None:
log.log("ERROR: Did not have a response from " + str(id)
+ ". File upload canceled for " + fpath + ".")
self.success = False
return False
if r.status_code != 201:
log.log("ERROR: Could not upload file " + fpath
+ ". Return code from printer " + str(r.status_code))
return False
data = r.json()
fname = data['files']['local']['name']
ext = get_extension(fname)
if ext in ['stl']:
job.state("slicing")
webapi.patch_job(job.to_web())
r = octopi.slice(url, key, fname, loc)
if r == None:
log.log("ERROR: Did not have a response from " + str(id)
+ ". Job upload canceled for job "
+ str(job_id) + ".")
self.success = False
return False
if r.status_code != 202:
log.log("ERROR: Job upload failed for " + str(job_id)
+ ". Return code from printer "
+ str(r.status_code))
self.success = False
return False
j = r.json()
rname = j.get('name')
r = octopi.get_one_file_info(url, key, rname, loc)
while r == None or r.status_code != 200:
#This is really fucking hacky
log.log("Could not retrieve file info for "
+ str(job.id))
sleep(10)
r = octopi.get_one_file_info(url, key, rname, loc)
job.set_remote_name(rname)
r = octopi.delete_file(url, key, fname, loc)
while r == None:
sleep(10)
r = octopi.delete_file(url, key, fname, loc)
elif ext in ['gcode', 'gco']:
r = octopi.get_one_file_info(url, key, fname, loc)
while r == None or r.status_code != 200:
#This is really fucking hacky
log.log("Could not retrieve file info for "
+ str(job.id))
sleep(10)
r = octopi.get_one_file_info(url, key, fname, loc)
job.set_remote_name(fname)
else:
self.success = False
return False
log.log("Completed job upload to " + str(id)
+ " for job " + str(job.id))
self.success = True
return True