Giter Club home page Giter Club logo

Comments (12)

viniciuschiele avatar viniciuschiele commented on July 1, 2024 1

Usually I create two files, one to run locally and another one for uwsgi/gunicorn/apache.

e.g:

# myapp.py
# my app logic goes here

def create_app():
    return Flask(__name__)
# run.py
# used to run locally

from myapp import create_app

if __name__ == '__main__':
    manager = Manager(create_app())
    manager.run()
# wsgi.py
# used to run on uwsgi/apache

from myapp import create_app

application = create_app()

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 1, 2024

Can you provide an example of what you are trying to accomplish?

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

I am trying to make a set of functions so that it can change the values in redis_db

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 1, 2024

I can't help you without an example, can you post here how you are initializing Flask and APSchduler?

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

I am using flask manager for developement server and apache2 for production server.

Below is the code for manag.py:
import os
from app import create_app, db
from app.models import User, Order, Contact, Wallet, Withdraw, Deposit, Transaction, Subscription
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
def make_shell_context():
return dict(app=app, db=db, User=User)
app = create_app('development')
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
if name == 'main':
scheduler.start()
manager.run()

Below is the code for intit.py:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy # using orm wrapper around sqlalchemy
from flask_login import LoginManager # for login sessions
from . import config # config file having different configurations
import redis
from flask_apscheduler import APScheduler
db = SQLAlchemy()
redis_db = redis.StrictRedis(host='localhost', port=6379, db=0)
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'auth.login' # Default login page, after any bad requests
scheduler = APScheduler()
import app.models
def create_app(config_name):
app = Flask(name)
app.config.from_object(config.config[config_name])
config.config[config_name].init_app(app)
login_manager.init_app(app)
db.init_app(app)
scheduler.init_app(app)
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
# attach routes and custom error pages herereturn app
return app
app = create_app('development')

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 1, 2024

Where do you start APScheduler?

The only place I see it in your code is here:

if name == 'main':
    scheduler.start()
    manager.run()

But I think this code above isn't being executed with Apache2.

I would suggest you to start APScheduler within create_app:

def create_app(config_name):
    ....    
    scheduler.start()

I hope it helps you out

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

I have not tested it on apache2, I was thinking first to test it on local flask server, that is why I had placed scheduler.start in the manager. If I put it inside the create_app then it returns that the schedular is already running. But with schedular.start() inside the manager, it gives the error that the job is already running

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 1, 2024

Just for testing, I've built this example similar to yours, it works well.

from flask import Flask
from flask_apscheduler import APScheduler
from flask_script import Manager, Shell

scheduler = APScheduler()


def create_app():
    app = Flask(__name__)
    scheduler.init_app(app)
    scheduler.start()
    return app


def make_shell_context():
    return dict(app=app)


app = create_app()

manager = Manager(app)
manager.add_command("shell", Shell(make_context=make_shell_context))

if __name__ == '__main__':
    manager.run()
python main.py runserver

Try to run it and see what happens.

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

Can it be that I am using different files for manager and init, it is happening

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 1, 2024

That makes no difference.

Before you got scheduler is already running because you are calling twice create_app('development')

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

creat_app('development') is for apache. Can you suggest any configuration that can work with both apache and flask?

from flask-apscheduler.

deveshaggrawal19 avatar deveshaggrawal19 commented on July 1, 2024

thanks for all the help

from flask-apscheduler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.