Giter Club home page Giter Club logo

Comments (13)

viniciuschiele avatar viniciuschiele commented on July 19, 2024

Are you using one single .py file to initialise the scheduler and to define your task? If so, it is not going to work because APScheduler will reload the same .py file and it will re-instantiate all your objects.

Split your project in two files, like app.py and tasks.py

app.py initialises Flask and APScheduler and in tasks.py you put your task methods.

I hope this works for you.

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

And also the way you built this code, the variable scheduler is not accessible within your task.

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

so are you saying that scheduler.delete_job('job1') is the right way of unscheduling a job?
and if jobstore in my config, like this
class Config(object):
JOBS = [
{
'id': 'job1',
'func': 'sjobs:job1',
'args': ("Shrey"),
'trigger': 'interval',
'seconds': 5
}
]
SCHEDULER_JOBSTORES = {
'default': SQLAlchemyJobStore(url='postgresql://postgres:postgres@localhost:5432/scheduler',tablename='apscheduler')
}

I have this config, with a jobstore(taken from example, just changed sqlite to postgres), do I have to give the jobstore name in the delete call, if yes then what it is? basically i want to delete the job from the jobstore

and one more doubt is, is there a way to delete a job from inside the job, without using the id....something like self.id gives id of the running job, or any workaround for that?

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

You don't need to give the jobstore name, just call delete_job passing the job name.

Unfortunately there is no way to get the current job within a job using self, if you really need that, you can open an issue for APScheduler

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

so does delete_job(id) deletes the job from jobstore, or it just stop executing it?

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

it will delete the job and stop executing it.

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

Thanks man...its working well

One more doubt that I have though, what about HA(High availability) is there anything can be done from APscheduler's point of view, like db sync or something which makes sure that it never goes down

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

No, APScheduler doesn't give any HA feature, you need to do it by yourself.

In my company we use uwsgi legion to keep one server as active and the others as stand by, so if the active server fails, uwsgi legion will start the APScheduler App in one of the other servers.

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

You are right, legion is for any application.

If the server fails it will bring up all apps that are part of this legion on the other server.
I'm not aware of the details because we have a system engineer that manages that for us.

As long as your jobs are stored in database, you shouldn't have any issue.

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

alright...thanks man
But before we close this discussion one naive doubt?
Say I dont have a legion setup done and I have a restful app which has apshceduler running in it, and I have 2 instances of the app running on 2 servers with the shared database, basically jobstore is same....so if a job gets scheduled, it will be served by both the apps right? or which ever server picks it up ony that will execute it...

from flask-apscheduler.

viniciuschiele avatar viniciuschiele commented on July 19, 2024

Hi,

Yeah, it will probably run by both apps.

from flask-apscheduler.

shr-chauhan avatar shr-chauhan commented on July 19, 2024

thanks man, we can close this

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.