Git Product home page Git Product logo

Comments (5)

dlux95 avatar dlux95 commented on June 30, 2024 4

You are missing the worker thread part in main. It is neccessary because this thread will call your functions. Right now there is no such thread in your app.

from schedule.

dylwhich avatar dylwhich commented on June 30, 2024 1

What are you trying to do? Do you want to have a flask API that can schedule jobs on command? For that you could add something like this:

def some_job():
    print("This job was scheduled from flask")

@app.route('/schedule/every/<int:count>/<period>')
def add_to_schedule(count=1, period=None):
    job = schedule.every(count)
    if count == 1:
        if period == 'day':
            job = job.day
        elif period == 'hour':
            job = job.hour
        elif period == 'minute':
            job = job.minute
        elif period == 'second':
            job = job.second
        else:
            return "Invalid period " + period
    else:
        if period == 'day':
            job = job.days
        elif period == 'hour':
            job = job.hours
        elif period == 'minute':
            job = job.minutes
        elif period == 'second':
            job = job.seconds
        else:
            return "Invalid period " + period
    job.do(some_job)
    return "OK"

And you could add more parameters and whatnot as necessary. Hope this helps!

from schedule.

abdounasser202 avatar abdounasser202 commented on June 30, 2024

thanks

from schedule.

prrraveen avatar prrraveen commented on June 30, 2024

@dylwhich I tired it but it did not work for me. Do I have to add something to main.
here is my code

import schedule
import time

app = Flask(__name__)

def some_job():
    print("This job was scheduled from flask")

@app.route('/schedule/every/<int:count>/<period>')
def add_to_schedule(count=1, period=None):
    job = schedule.every(1).seconds.do(some_job)
    return "OK"

if __name__ == "__main__":
    app.run(debug=True)

from schedule.

anselal avatar anselal commented on June 30, 2024

I want to do something similar to the example provided by @abdounasser202
and not use an endpoint like @dylwhich mentioned.
I want to schedule a task in the background with Flask is started.
Any help ?

from schedule.

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.