def create_app(config): app = Flask(__name__) DB.init() register_blueprints(app) for job_name in ['job1', 'job2', 'job3']: new_job = Job(name=job_name) new_job.insert() return app
def create_app(new): app = Flask(__name__) bootstrap = Bootstrap(app) app.config.from_object(Config) #根据config启用mongodb if Config.MongoDbEnable: DB.init() for job_name in ['job1', 'job2', 'job3']: new_job = Job(name=job_name) new_job.insert() sentence2vec.init() NewsData.init() register_blueprints(app) return app
def view_job_csv(service_id, job_id): job = Job.from_id(job_id, service_id=service_id) filter_args = parse_filter_args(request.args) filter_args['status'] = set_status_filters(filter_args) return Response( stream_with_context( generate_notifications_csv( service_id=service_id, job_id=job_id, status=filter_args.get('status'), page=request.args.get('page', 1), page_size=5000, format_for_csv=True, template_type=job.template_type, ) ), mimetype='text/csv', headers={ 'Content-Disposition': 'inline; filename="{} - {}.csv"'.format( job.template['name'], format_datetime_short(job.created_at) ) } )
def view_job(service_id, job_id): job = Job.from_id(job_id, service_id=current_service.id) if job.cancelled: abort(404) filter_args = parse_filter_args(request.args) filter_args['status'] = set_status_filters(filter_args) just_sent_message = 'Your {} been sent. Printing starts {} at 5:30pm.'.format( 'letter has' if job.notification_count == 1 else 'letters have', printing_today_or_tomorrow(job.created_at)) return render_template( 'views/jobs/job.html', job=job, status=request.args.get('status', ''), updates_url=url_for( ".view_job_updates", service_id=service_id, job_id=job.id, status=request.args.get('status', ''), ), partials=get_job_partials(job), just_sent=request.args.get('just_sent') == 'yes', just_sent_message=just_sent_message, )
def create_job(*, account: Account, title: str, description: str, seniority_level: str, employment_type: str, recruitment_url: str, cities: list, skills: list) -> list: company_account_check(account) j = Job(company=get_company_account(account), title=title, description=description, seniority_level=seniority_level, employment_type=employment_type, recruitment_url=recruitment_url, published_date=date.today()) j.save() j.cities.add(*cities) j.skills.add(*skills) return list_job(id=account.id)
def submit(): form = JobSubmissionForm() if form.validate_on_submit(): jobs = Job( title=form.title.data, company=form.company.data, location=form.location.data, description=form.description.data, skills=form.skills.data, website=form.website.data, contact=form.contact.data, employment=form.employment.data, on_site=form.on_site.data, ) jobs.user_id = current_user.id jobs.created_at = datetime.utcnow() db.session.add(jobs) db.session.commit() return redirect(url_for("job.listing")) return render_template("/job/submit.html", title="job submission", form=form)
def update_status(self, db: Session, *, db_obj: Job, status: JobStatus) -> Job: if db_obj.status is status: pass log_obj = JobLog(job_id=db_obj.id, from_status=db_obj.status, to_status=status) db.add(log_obj) db_obj.status = status db.add(db_obj) db.commit() db.refresh(db_obj) return db_obj
def test_add_rate_to_job_preserves_initial_fields(): resp = Job({ 'statistics': [ { 'status': 'failed', 'count': 0 }, { 'status': 'delivered', 'count': 0 }, ], 'id': 'foo', }) assert resp.notifications_failed == resp.notifications_delivered == resp.failure_rate == 0 assert resp.id == 'foo'
def fix_job_def(self, job_def): if job_def.get('trigger') == 'data': job_def['run_date'] = job_def.get('run_date') or None elif job_def.get('trigger') == 'cron': job_def['hour'] = job_def.get('hour', "*") job_def['minute'] = job_def.get('minute', "*") job_def['week'] = job_def.get('week', "*") job_def['day'] = job_def.get('day', "*") job_def['month'] = job_def.get('month, "*') elif job_def.get('trigger') == 'interval': job_def['seconds'] = job_def.get('seconds', "*") else: if job_def.get("andTri"): job_def['trigger'] = AndTrigger([ job_def.pop("andTri", None), ]) Job().save_job(job_def=job_def) return job_def
def test_add_rate_to_job_calculates_rate(failed, delivered, expected_failure_rate): resp = Job({ 'statistics': [ { 'status': 'failed', 'count': failed }, { 'status': 'delivered', 'count': delivered }, ], 'id': 'foo', }) assert resp.failure_rate == expected_failure_rate
def cancel_letter_job(service_id, job_id): if request.method == 'POST': job = Job.from_id(job_id, service_id=service_id) if job.status != 'finished' or job.notifications_created < job.notification_count: flash("We are still processing these letters, please try again in a minute.", 'try again') return view_job(service_id, job_id) try: number_of_letters = job.cancel() except HTTPError as e: flash(e.message, 'dangerous') return redirect(url_for('main.view_job', service_id=service_id, job_id=job_id)) flash("Cancelled {} letters from {}".format( format_thousands(number_of_letters), job.original_file_name ), 'default_with_tick') return redirect(url_for('main.service_dashboard', service_id=service_id)) flash("Are you sure you want to cancel sending these letters?", 'cancel') return view_job(service_id, job_id)
def cadastroJobs(id): if not current_user.is_authenticated: return redirect(url_for('login')) form = CadastroJobForm() if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(id=current_user.id).first() identifier = randomword(200) new_job = Job(form.name.data, form.category.data, form.value.data, form.description.data, form.others.data, current_user.id, user.nick_name, identifier) db.session.add(new_job) db.session.commit() return redirect(url_for('index', id=current_user)) else: flash("Erro ao cadastrar serviço") print(form.name.errors) print(form.category.errors) print(form.value.errors) print(form.description.errors) print(form.others.errors) return render_template('cadastroJobs.html', form=form, id=id)
def test_client_parses_empty_job_stats(mocker): service_id = 'service_id' job_id = 'job_id' expected_data = { 'data': { 'status': 'finished', 'template_version': 3, 'id': job_id, 'updated_at': '2016-08-24T08:29:28.332972+00:00', 'service': service_id, 'processing_finished': '2016-08-24T08:11:48.676365+00:00', 'statistics': [], 'original_file_name': 'test-notify-email.csv', 'created_by': { 'name': '*****@*****.**', 'id': '3571f2ae-7a39-4fb4-9ad7-8453f5257072' }, 'created_at': '2016-08-24T08:09:56.371073+00:00', 'template': 'c0309261-9c9e-4530-8fed-5f67b02260d2', 'notification_count': 80, 'processing_started': '2016-08-24T08:09:57.661246+00:00' } } expected_url = '/service/{}/job/{}'.format(service_id, job_id) mock_get = mocker.patch( 'app.notify_client.job_api_client.JobApiClient.get', return_value=expected_data) result = Job.from_id(job_id, service_id=service_id) mock_get.assert_called_once_with(url=expected_url, params={}) assert result.notifications_requested == 0 assert result.notifications_sent == 0 assert result.notification_count == 80 assert result.notifications_failed == 0
def add_job(): new_job = Job(tittle='我是第二批测试用的工作', reward='80/周', place='朝阳', settlement=2, isBagEating=1, encase=2, isTrafficSubsidy=2, royalty=1, content='这是测试工作的内容:1.必须按时报到。2.工作前续联系负责人获取工作群号', detailPlace='朝阳广场附近', startTime="2021-03-15", endTime="2021-03-19", fromCompany="中国电信南宁分公司", recruitNum=1, sex=3, type="其他", withPeople="王女士", status=2) db.session.add(new_job) db.session.commit() print(f"Job{new_job.id}: {new_job}") res = db.session.query(Job).all() print("\n".join([str(p) for p in res]))
def add_job(): """Adds job4 to the database.""" new_job = Job(name='job4') new_job.insert() return ('', 204)
def addJob(): i = 1 while i <= 3: job = Job() job.tittle = '我是第二批测试用的工作' + str(i) job.reward = '80/周' job.place = '朝阳' job.settlement = 2 job.isBagEating = 1 job.encase = 2 job.isTrafficSubsidy = 2 job.royalty = 1 job.content = '这是测试工作的内容:1.必须按时报到。2.工作前续联系负责人获取工作群号' job.detailPlace = '朝阳广场附近' job.startTime = "2020-03-15" job.endTime = "2020-03-19" job.fromCompany = "中国电信南宁分公司" job.recruitNum = 1 job.sex = 3 job.type = "其他" job.withPeople = "王女士" db.session.add(job) db.session.commit() i += 1
def view_job_updates(service_id, job_id): job = Job.from_id(job_id, service_id=service_id) return jsonify(**get_job_partials(job))
def cancel_job(service_id, job_id): Job.from_id(job_id, service_id=service_id).cancel() return redirect(url_for('main.service_dashboard', service_id=service_id))
def add_default_job(): """Adds job5 to the database.""" new_job = Job(name='job50') new_job.insert() return ('', 204)