Comments (9)
Hi,
You can pass in your own APScheduler object to Flask-APScheduler.
from apscheduler.schedulers.background import BackgroundScheduler
from flask_apscheduler import APScheduler
scheduler = APScheduler(BackgroundScheduler())
Does it help you? If not, show me the code you are doing with APScheduler so I can show you how to do the same with Flask-APScheduler.
Cheers
from flask-apscheduler.
Thanks, got it
this is fine, but somehow I am not able to get it working on a rest post request
example structure,
api
v2_0
scheduler.py
app.py
in scheduler.py, I have a post method on a URL where I am doing this
scheduler.add_job(id='12344perform',func='background_tasks.schedule:immediate_task',trigger='interval',seconds=5)
in app.py
from flask_apscheduler import APScheduler
scheduler = APScheduler()
def create_app(config_name):
scheduler.init_app(app)
scheduler.start()
Just given the apscheduler related configuration, running it on a local flask server as of now, so when i run it create_app method gets triggered.
Dont know what am I doing wrong, but the task(background_tasks.schedule:immediate_task) is not getting triggered when I hit the URL...
Thanks for any help with this
from flask-apscheduler.
this is the structure
api-
----v2_0-
--------scheduler.py
background_tasks-
----schedule.py
app.py
from flask-apscheduler.
Hi,
If I understood well, you have an flask endpoint that adds a new task in APScheduler, this task is executed on background every 5 seconds.
This code below is an example of this and it works well for me:
from datetime import datetime
from flask import Flask, Response
from flask_apscheduler import APScheduler
def job1():
print(datetime.now())
app = Flask(__name__)
scheduler = APScheduler()
@app.route('/add_task', methods=['POST'])
def add_task():
task_id = str(datetime.now())
scheduler.add_job(task_id, 'rest:job1', trigger='interval', seconds=5)
return Response()
if __name__ == '__main__':
scheduler.init_app(app)
scheduler.start()
app.run()
curl -X POST http://127.0.0.1:5000/add_task
Maybe you could enable the logs for APScheduler to see what's going on.
from flask-apscheduler.
yea task is running, but somehow not able to produce the logs for the scheduler
i tried with an example, and i used this basicConfig like this
import logging
logging.basicConfig(filename='/var/log/testsched', level=logging.DEBUG,format='[%(asctime)s]: %(levelname)s : %(message)s')
which worked fine for me, but somehow in my project log file itself is not getting generated
from flask-apscheduler.
so logging configuration is kinda tricky, so I already have a logging setup which I dont want to tweak, so because of that logging.basicConfig() is not working, can you help me in figuring out how can I make it work, without really disturbing the current logging functionality.
This is my logging_config.py file:
'''
set and configure a common module logger
'''
import logging
import logging.handlers
import os
from common import configuration
log_folder = configuration.system['log_folder']
if not os.path.exists(log_folder): os.mkdir(log_folder)
applogger = logging.getLogger(configuration.system['app_name'])
#do not propogate logs to the root logger
applogger.propagate = False
logging_level = logging.DEBUG
def configure_app_logger(debug=False):
'''configure common moudle logger'''
global applogger
global logging_level
if debug:
log_level = logging.DEBUG
log_formatter = logging.Formatter(
fmt='%(asctime)s : %(levelname)-8s %(message)-81s <- %(module)s.%(funcName)s, line %(lineno)d',
datefmt='%d/%b/%y %I:%M:%S%p')
else:
log_level = logging.INFO
log_formatter = logging.Formatter(fmt='%(asctime)s : %(levelname)-8s %(message)s',
datefmt='%d/%b/%y %I:%M:%S%p')
logging_level = log_level
file_handler = logging.handlers.WatchedFileHandler(
os.path.join(log_folder, '{a}.log'.format(a=configuration.system['app_name'])))
file_handler.setLevel(log_level)
file_handler.setFormatter(log_formatter)
console_handler = logging.StreamHandler()
console_handler.setLevel(log_level)
console_handler.setFormatter(log_formatter)
applogger.setLevel(log_level)
applogger.addHandler(file_handler)
applogger.addHandler(console_handler)
from flask-apscheduler.
If I'm not wrong, APScheduler logs its logs in the logger name apscheduler.executors.default
I think you need to set up a logger with this name.
logger = logging.getLogger('apscheduler.executors.default')
logger.addHandler(...)
logger.addHandler(...)
I'm not sure this code above will work, that is just a guess.
from flask-apscheduler.
Bang on...thanks mate
did not know about apscheduler.executors.default, as basicConfig worked for me so never looked into this....so now I created a new logger for scheduler with a different set of config and all works well for me now
Cheers
from flask-apscheduler.
I'm glad to hear that.
Cheers
from flask-apscheduler.
Related Issues (20)
- Running job causes detachedinstanceerror HOT 3
- Use Codecov in informational mode HOT 1
- APScheduler not working with gunicorn eventlet HOT 6
- Flask 2.3.2 causing KeyError: 'JSONIFY_PRETTYPRINT_REGULAR' HOT 1
- Flask-APScheduler multiple jobs running at the same time when having multiple workers HOT 1
- [RFE] Package python3-flask-apscheduler into RPM
- KeyError: 'JSONIFY_PRETTYPRINT_REGULAR' when running Flask as a development server HOT 2
- Apscheduler not working with flask debug=True & --no-reload
- Flask 3.0.0 support HOT 1
- Behaviour of processpool HOT 1
- Key Error while passing redis instance as arg HOT 2
- Can't start BlockingScheduler as daemon in debug mode
- Issue with sqlalchemy (cannot join current thread and working outside of app context) HOT 4
- python3-flask-APScheduler_1.13.0.bb HOT 4
- Can I use hive database to restore jobs? HOT 2
- Coroutine as argument
- use api add task func which is not defined in the app start script failed HOT 2
- alembic migrations
- ModuleNotFoundError: No module named 'flask_apscheduler' HOT 2
- Adding a pyproject.toml to ensure compliance with updates to pip
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-apscheduler.