def email_job_show(request,job_id): job = EMailJob.get_by_id(int(job_id)) if job is None: raise Http404 sub_list = EMailSubJob.all().ancestor(job) job_data = EMailJobData.all().ancestor(job).get() return render_to_response('emails/email_job_show.html', RequestContext(request, { 'sub_list': sub_list, 'job':job, 'job_data':job_data}))
def fire_email_subjob(request,subjob_key): if not getConfigBool('ENABLE_MAIL_JOBS',False): logging.info('ENABLE_MAIL_JOBS != True, ignore') return HttpResponse('disabled') sub_job = EMailSubJob.get(subjob_key) if sub_job is None: logging.info('no sub_job') raise Http404 job = EMailJob.get(sub_job.parent_key()) if job is None: logging.info('no job') raise Http404 job_data = EMailJobData.all().ancestor(job).get() if job_data is None: logging.info('no job_data') raise Http404 try: email = EmailMessage(job_data.data) email.sender = job_data.sender email.to = job_data.sender email.check_initialized() except: logging.info("can't init email! %s"%sys.exc_info()[1]) sub_job.status = 'error' sub_job.status_info = "can't init email message - %s"%sys.exc_info()[1] sub_job.save() return HttpResponse('error') logging.info('processing mail sub job:%s'%sub_job) sub_job.status = 'send' sub_job.save() for e in sub_job.emails: logging.info('sending email to %s'%e) try: email.to = e email.send() sub_job.emails_done.extend([e]) except: logging.info("can't init email! %s"%sys.exc_info()[1]) sub_job.emails_error.extend([e]) sub_job.status = 'done' sub_job.save() logging.info('result:%s'%sub_job) return HttpResponse('ok')
def email_job_start_task(request,job_id): job = EMailJob.get_by_id(int(job_id)) if job is None: raise Http404 logging.info('starting mail job:%s'%job) if job.status != 'prepare': HttpResponse('ign') sub_list = EMailSubJob.all().ancestor(job) for s in sub_list: logging.info('start: %s'%s) taskqueue.add(url='/tasks/fire_email_subjob/%s/'%s.key(), method='GET') logging.info('end') return HttpResponse('ok')
def email_job_prepare(request,job_id): job = EMailJob.get_by_id(int(job_id)) if job is None: raise Http404 logging.info('prepare mail job:%s'%job) if job.status != 'new': HttpResponse('ign') job_data = EMailJobData.all().ancestor(job).get() for i in range(0,len(job_data.emails),job_data.split_count): subjob = EMailSubJob(parent = job) subjob.emails_offset = i subjob.emails = job_data.emails[i:i+job_data.split_count] subjob.emails_count = len(subjob.emails) subjob.status = 'prepare' subjob.save() logging.info('subjob:%s'%subjob) job.status = 'prepare' job.save() return HttpResponse('ok')