本文整理汇总了Python中flask_apscheduler.APScheduler.start方法的典型用法代码示例。如果您正苦于以下问题:Python APScheduler.start方法的具体用法?Python APScheduler.start怎么用?Python APScheduler.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_apscheduler.APScheduler
的用法示例。
在下文中一共展示了APScheduler.start方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHTTPBasicAuth
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestHTTPBasicAuth(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
self.scheduler.auth = HTTPBasicAuth()
self.scheduler.api_enabled = True
self.scheduler.init_app(self.app)
self.scheduler.start()
self.scheduler.authenticate(self._authenticate)
self.client = self.app.test_client()
def _authenticate(self, auth):
return auth['username'] == 'test' and auth['password'] == 'test'
def test_valid_credentials(self):
headers = {'Authorization': 'Basic ' + base64.b64encode(b'test:test').decode('ascii')}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 200)
def test_invalid_credentials(self):
headers = {'Authorization': 'Basic ' + base64.b64encode(b'guest:guest').decode('ascii')}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')
def test_invalid_header_format(self):
headers = {'Authorization': 'Basic 1231234'}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')
def test_missing_credentials(self):
response = self.client.get(self.scheduler.api_prefix + '')
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')
示例2: stacosys_server
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
def stacosys_server(config_pathname):
app = Flask(__name__)
config.initialize(config_pathname, app)
# configure logging
logger = logging.getLogger(__name__)
configure_logging(logging.INFO)
logging.getLogger("werkzeug").level = logging.WARNING
logging.getLogger("apscheduler.executors").level = logging.WARNING
# initialize database
from core import database
database.setup()
# cron email fetcher
app.config.from_object(
JobConfig(
config.getInt(config.MAIL_POLLING), config.getInt(config.COMMENT_POLLING)
)
)
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
logger.info("Start Stacosys application")
# generate RSS for all sites
from core import rss
rss.generate_all()
# start Flask
from interface import api
from interface import form
logger.debug("Load interface %s" % api)
logger.debug("Load interface %s" % form)
app.run(
host=config.get(config.HTTP_HOST),
port=config.get(config.HTTP_PORT),
debug=False,
use_reloader=False,
)
示例3: TestAPIPrefix
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestAPIPrefix(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
self.scheduler.api_enabled = True
self.scheduler.api_prefix = '/api'
self.scheduler.init_app(self.app)
self.scheduler.start()
self.client = self.app.test_client()
def test_api_prefix(self):
response = self.client.get(self.scheduler.api_prefix + '/jobs')
self.assertEqual(response.status_code, 200)
def test_invalid_api_prefix(self):
response = self.client.get('/invalidapi/jobs')
self.assertEqual(response.status_code, 404)
示例4: TestScheduler
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestScheduler(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
def test_running(self):
self.assertFalse(self.scheduler.running)
self.scheduler.start()
self.assertTrue(self.scheduler.running)
def test_start_with_allowed_hosts(self):
self.app.config['SCHEDULER_ALLOWED_HOSTS'] = ['any_server_name']
self.scheduler.init_app(self.app)
self.scheduler.start()
self.assertFalse(self.scheduler.running)
def test_start_without_allowed_hosts(self):
self.app.config['SCHEDULER_ALLOWED_HOSTS'] = []
self.scheduler.init_app(self.app)
self.scheduler.start()
self.assertFalse(self.scheduler.running)
def test_shutdown(self):
self.scheduler.init_app(self.app)
self.scheduler.start()
self.assertTrue(self.scheduler.running)
self.scheduler.shutdown()
self.assertFalse(self.scheduler.running)
def test_load_jobs_from_config(self):
self.app.config['JOBS'] = [
{
'id': 'job1',
'func': 'tests.test_api:job1',
'trigger': 'interval',
'seconds': 10
}
]
self.scheduler.init_app(self.app)
job = self.scheduler.get_job('job1')
self.assertIsNotNone(job)
def test_task_decorator(self):
@self.scheduler.task('interval', seconds=10, id='job1')
def decorated_job():
pass
job = self.scheduler.get_job('job1')
self.assertIsNotNone(job)
示例5: TestEndpointPrefix
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestEndpointPrefix(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
self.scheduler.api_enabled = True
self.scheduler.endpoint_prefix = 'api.'
self.scheduler.init_app(self.app)
self.scheduler.start()
self.client = self.app.test_client()
def test_endpoint_prefix(self):
with self.scheduler.app.test_request_context():
valid_url = True if url_for(self.scheduler.endpoint_prefix + 'get_scheduler_info') else False
self.assertTrue(valid_url)
def test_invalid_endpoint_prefix(self):
with self.scheduler.app.test_request_context():
try:
valid_url = url_for('get_scheduler_info')
except BuildError as _:
valid_url = False
self.assertFalse(valid_url)
示例6: srmail_server
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
def srmail_server(config_pathname):
app = Flask(__name__)
config.initialize(config_pathname, app)
# configure logging
logger = logging.getLogger(__name__)
configure_logging(logging.INFO)
# initialize database
from core import database
database.setup()
# cron email fetcher
app.config.from_object(JobConfig(config.getInt(config.IMAP_POLLING)))
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
logger.info("Starting SRMAIL application")
# start Flask
from interface import api
logger.debug("Load interface %s" % api)
app.run(
host=config.get(config.HTTP_HOST),
port=config.get(config.HTTP_PORT),
debug=False,
use_reloader=False,
)
# Exit application
logger.info("Stopping SRMAIL application")
示例7: task_init
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
def task_init():
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
refresh()
示例8: Config
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
from flask import Flask
from flask_apscheduler import APScheduler
class Config(object):
JOBS = [
{
'id': 'job1',
'func': '__main__:job1',
'args': (1, 2),
'trigger': 'interval',
'seconds': 10
}
]
SCHEDULER_VIEWS_ENABLED = True
def job1(a, b):
print(str(a) + ' ' + str(b))
app = Flask(__name__)
app.config.from_object(Config())
app.debug = True
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
app.run()
示例9: TestViews
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestViews(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.app.config['SCHEDULER_VIEWS_ENABLED'] = True
self.scheduler = APScheduler(app=self.app)
self.scheduler.start()
self.client = self.app.test_client()
def test_add_job(self):
job = {
'id': 'job1',
'func': 'test_views:job1',
'trigger': 'date',
'run_date': '2020-12-01T12:30:01+00:00',
}
response = self.client.post('/scheduler/jobs', data=json.dumps(job))
self.assertEqual(response.status_code, 200)
job2 = json.loads(response.get_data(as_text=True))
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('run_date'), job2.get('run_date'))
def test_delete_job(self):
self.__add_job()
response = self.client.delete('/scheduler/jobs/job1')
self.assertEqual(response.status_code, 204)
response = self.client.get('/scheduler/jobs/job1')
self.assertEqual(response.status_code, 404)
def test_get_job(self):
job = self.__add_job()
response = self.client.get('/scheduler/jobs/job1')
self.assertEqual(response.status_code, 200)
job2 = json.loads(response.get_data(as_text=True))
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('minutes'), job2.get('minutes'))
def test_get_all_jobs(self):
job = self.__add_job()
response = self.client.get('/scheduler/jobs')
self.assertEqual(response.status_code, 200)
jobs = json.loads(response.get_data(as_text=True))
self.assertEqual(len(jobs), 1)
job2 = jobs[0]
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('minutes'), job2.get('minutes'))
def test_update_job(self):
job = self.__add_job()
data_to_update = {
'args': [1]
}
response = self.client.patch('/scheduler/jobs/job1', data=json.dumps(data_to_update))
self.assertEqual(response.status_code, 200)
job2 = json.loads(response.get_data(as_text=True))
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(data_to_update.get('args'), job2.get('args'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('minutes'), job2.get('minutes'))
def test_pause_and_resume_job(self):
self.__add_job()
response = self.client.post('/scheduler/jobs/job1/pause')
self.assertEqual(response.status_code, 200)
job = json.loads(response.get_data(as_text=True))
self.assertIsNone(job.get('next_run_time'))
response = self.client.post('/scheduler/jobs/job1/resume')
self.assertEqual(response.status_code, 200)
job = json.loads(response.get_data(as_text=True))
self.assertIsNotNone(job.get('next_run_time'))
def __add_job(self):
job = {
'id': 'job1',
'func': 'test_views:job1',
#.........这里部分代码省略.........
示例10: initSchedule
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
def initSchedule():
app.config.from_object(Config())
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
print("Scheduler Initialized\n")
示例11: TestAPI
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import start [as 别名]
class TestAPI(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
self.scheduler.api_enabled = True
self.scheduler.init_app(self.app)
self.scheduler.start()
self.client = self.app.test_client()
def test_scheduler_info(self):
response = self.client.get(self.scheduler.api_prefix)
self.assertEqual(response.status_code, 200)
info = json.loads(response.get_data(as_text=True))
self.assertIsNotNone(info['current_host'])
self.assertEqual(info['allowed_hosts'], ['*'])
self.assertTrue(info['running'])
def test_add_job(self):
job = {
'id': 'job1',
'func': 'tests.test_api:job1',
'trigger': 'date',
'run_date': '2020-12-01T12:30:01+00:00',
}
response = self.client.post(self.scheduler.api_prefix + '/jobs', data=json.dumps(job))
self.assertEqual(response.status_code, 200)
job2 = json.loads(response.get_data(as_text=True))
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('run_date'), job2.get('run_date'))
def test_add_conflicted_job(self):
job = {
'id': 'job1',
'func': 'tests.test_api:job1',
'trigger': 'date',
'run_date': '2020-12-01T12:30:01+00:00',
}
response = self.client.post(self.scheduler.api_prefix + '/jobs', data=json.dumps(job))
self.assertEqual(response.status_code, 200)
response = self.client.post(self.scheduler.api_prefix + '/jobs', data=json.dumps(job))
self.assertEqual(response.status_code, 409)
def test_add_invalid_job(self):
job = {
'id': None,
}
response = self.client.post(self.scheduler.api_prefix + '/jobs', data=json.dumps(job))
self.assertEqual(response.status_code, 500)
def test_delete_job(self):
self.__add_job()
response = self.client.delete(self.scheduler.api_prefix + '/jobs/job1')
self.assertEqual(response.status_code, 204)
response = self.client.get(self.scheduler.api_prefix + '/jobs/job1')
self.assertEqual(response.status_code, 404)
def test_delete_job_not_found(self):
response = self.client.delete(self.scheduler.api_prefix + '/jobs/job1')
self.assertEqual(response.status_code, 404)
def test_get_job(self):
job = self.__add_job()
response = self.client.get(self.scheduler.api_prefix + '/jobs/job1')
self.assertEqual(response.status_code, 200)
job2 = json.loads(response.get_data(as_text=True))
self.assertEqual(job.get('id'), job2.get('id'))
self.assertEqual(job.get('func'), job2.get('func'))
self.assertEqual(job.get('trigger'), job2.get('trigger'))
self.assertEqual(job.get('minutes'), job2.get('minutes'))
def test_get_job_not_found(self):
response = self.client.get(self.scheduler.api_prefix + '/jobs/job1')
self.assertEqual(response.status_code, 404)
def test_get_all_jobs(self):
job = self.__add_job()
response = self.client.get(self.scheduler.api_prefix + '/jobs')
self.assertEqual(response.status_code, 200)
jobs = json.loads(response.get_data(as_text=True))
self.assertEqual(len(jobs), 1)
job2 = jobs[0]
self.assertEqual(job.get('id'), job2.get('id'))
#.........这里部分代码省略.........