def cast(self): #schedule the campaign url = Campaignpages.query.filter_by(campaign_id=self.id, index=0).first().page.url base_url = 'https://%s' % self.domain.domain if self.ssl else 'http://%s' % self.domain.domain mail = self.profile.get_mailer() #self.profile.schedule_campaign(email=self.email, targets=self.list.targets, campaign_id=self.id, base_url=base_url, interval=self.send_interval, batch_size=self.batch_size, start_time=self.start_time, data=data, ip=self.server.ip, port=self.server.port, url=url) job_id = str(self.id) # Schedule the campaign and intialize it current_jobs = sched.get_jobs() # In case the batch size or interval are blank, set them appropriately if not self.batch_size: self.batch_size = len(self.list.targets) if not self.send_interval: self.send_interval = 0 db.session.commit() # Schedule the campaign and intialize it try: if self.start_time < datetime.now(): # schedule campaign to be run in 8 seconds from current timme - anything less and the campaign will wait 1 interval before sending the first batch of emails. Does not affect sending without batches or future start times sched.add_job(func=self.run_campaign, trigger='interval', minutes=int(self.send_interval), id=job_id, start_date=datetime.now() + timedelta(0, 8), replace_existing=True, args=[mail, base_url, url]) else: sched.add_job(func=self.run_campaign, trigger='interval', minutes=int(self.send_interval), id=job_id, start_date=self.start_time, replace_existing=True, args=[mail, base_url, url]) except Exception: app.logger.exception( f'Error scheduling campaign {self.name} (ID: {self.id})') else: app.logger.info( f'Scheduled campaign {self.name} (ID: {self.id}) to start at {self.start_time} - Sending {len(self.list.targets)} emails in batches of {self.batch_size} every {self.send_interval} minutes' ) self.status = 'Scheduled' db.session.commit()
else: case += 1 except: case += 1 resu_cout = TestResult.query.filter_by(status=False).all() reslut_list = [] for result in range(len(resu_cout)): try: if resu_cout[result].projects.status == False: reslut_list.append(resu_cout[result]) else: result += 1 except: result += 1 My_task = [] for job in sched.get_jobs(): job_task = Task.query.filter_by(id=job.id, status=False).first() if job_task.makeuser == current_user.id: My_task.append({ 'taskname': job_task.taskname, 'next_run': job.next_run_time.strftime('%Y-%m-%d %H:%M:%S '), 'run_status': job_task.yunxing_status, 'id': job_task.id }) project_cout = Project.query.filter_by(status=False).count() model_cout = Model.query.filter_by(status=False).count() return render_template('home/index.html',
def profile_list(): data = Profile().retrieve(jobs=sched.get_jobs()) return render_template('profile.html', profiles=data)
def unschedule_job(p_id): for job in sched.get_jobs(): if job.name == 'wj_%s' % p_id: sched.unschedule_job(job) break