当前位置: 首页>>代码示例>>Python>>正文


Python flask_apscheduler.APScheduler类代码示例

本文整理汇总了Python中flask_apscheduler.APScheduler的典型用法代码示例。如果您正苦于以下问题:Python APScheduler类的具体用法?Python APScheduler怎么用?Python APScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了APScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_app

def create_app():
    app = Flask(__name__)

    if 'AXE_CONFIG' in os.environ:
        app.config.from_envvar('AXE_CONFIG')
    else:
        logger.warning('Missing config: AXE_CONFIG.')

    app.config.update({
        'SCHEDULER_API_ENABLED': True,
        'JOBS': [
            {
                'func': count,
                'trigger': 'interval',
                'seconds': 3,
                'id': 'count',
            }
        ]
    })
    scheduler = APScheduler()
    scheduler.init_app(app)

    app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
        '/metrics': make_wsgi_app()
    })

    return app
开发者ID:soasme,项目名称:axe,代码行数:27,代码来源:axe.py

示例2: setUp

 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()
开发者ID:viniciuschiele,项目名称:flask-apscheduler,代码行数:7,代码来源:test_api.py

示例3: TestAPIPrefix

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)
开发者ID:viniciuschiele,项目名称:flask-apscheduler,代码行数:17,代码来源:test_api.py

示例4: stacosys_server

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,
    )
开发者ID:kianby,项目名称:stacosys,代码行数:46,代码来源:run.py

示例5: TestHTTPBasicAuth

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"')
开发者ID:viniciuschiele,项目名称:flask-apscheduler,代码行数:35,代码来源:test_api.py

示例6: TestEndpointPrefix

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)
开发者ID:viniciuschiele,项目名称:flask-apscheduler,代码行数:22,代码来源:test_api.py

示例7: srmail_server

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")
开发者ID:kianby,项目名称:srmail,代码行数:36,代码来源:run.py

示例8: TestAPI

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'))
#.........这里部分代码省略.........
开发者ID:viniciuschiele,项目名称:flask-apscheduler,代码行数:101,代码来源:test_api.py

示例9: TestScheduler

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_views:job1',
                'trigger': 'interval',
                'seconds': 10
            }
        ]

        self.scheduler.init_app(self.app)
        job = self.scheduler.get_job('job1')
        self.assertIsNotNone(job)
开发者ID:JWhy,项目名称:flask-apscheduler,代码行数:42,代码来源:test_scheduler.py

示例10: setUp

 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()
开发者ID:tshauck,项目名称:flask-apscheduler,代码行数:6,代码来源:test_views.py

示例11: APScheduler

flask.config['JOBS'] = [
        {
            'id': 'buildNewlyAddedRSSFeed',
            'func': 'server.views:buildNewlyAddedRSSFeed',
            'trigger': 'interval',
            'seconds': (60*60)
        },
        {
            'id': 'buildNewlyAddedAtomFeed',
            'func': 'server.views:buildNewlyAddedAtomFeed',
            'trigger': 'interval',
            'seconds': (60*60)
        },
        {
            'id': 'buildNewlyAddedRSSFeedAtStartup',
            'func': 'server.views:buildNewlyAddedRSSFeed'
        },
        {
            'id': 'buildNewlyAddedAtomFeedAtStartup',
            'func': 'server.views:buildNewlyAddedAtomFeed'
        }
    ]
flask.config['SCHEDULER_VIEWS_ENABLED'] = True
flask.debug = True

scheduler = APScheduler()
scheduler.init_app(flask)
scheduler.start()

if __name__ == '__main__':
    flask.run(host = '0.0.0.0', port = 8000)
开发者ID:cpwhidden,项目名称:StuffMart,代码行数:31,代码来源:runserver.py

示例12: TestViews

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',
#.........这里部分代码省略.........
开发者ID:tshauck,项目名称:flask-apscheduler,代码行数:101,代码来源:test_views.py

示例13: Flask

from flask import Flask
app = Flask(__name__)

#APScheduler
from flask_apscheduler import APScheduler
from myapp.jobs import Config
app.config.from_object(Config())
scheduler = APScheduler()
scheduler.init_app(app)

from myapp import views

import myapp.services
services.request_heartbeat()
services.check_traffic_status()
services.check_weather_status()
开发者ID:fzsun316,项目名称:thub-db-virtualization,代码行数:16,代码来源:__init__.py

示例14: initSchedule

def initSchedule():
	app.config.from_object(Config())
	scheduler = APScheduler()
	scheduler.init_app(app)
	scheduler.start()
	print("Scheduler Initialized\n")
开发者ID:allenwwg,项目名称:easytrader,代码行数:6,代码来源:FlaskServer.py

示例15: Flask

#! usr/bin/env python

"""hacky project"""
import json

from flask import Flask, request
from flask_apscheduler import APScheduler

from reminder import add_reminder, display_time

app = Flask(__name__)
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()

scheduler.add_job(id='tick', func=display_time,
    trigger='interval', seconds=30)

@app.route("/", methods=['POST'])
def get_reminder():
    print(request.args)
    reminder_text = request.args['text']
    reminder_delay = int(request.args['delay'])
    add_reminder(scheduler, reminder_text, reminder_delay)
    return json.dumps({
        'status':'success',
        'text': reminder_text,
        'delay': reminder_delay
        })

if __name__ == "__main__":
开发者ID:manugarri,项目名称:raspberry_reminder,代码行数:31,代码来源:reminder_server.py


注:本文中的flask_apscheduler.APScheduler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。