celery-scheduler icon indicating copy to clipboard operation
celery-scheduler copied to clipboard

[QUESTION] How to add API calls?

Open scheung38 opened this issue 6 years ago • 0 comments

if i have a Flask API call

class Contact(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    userName = db.Column(db.String(100), unique=True)

@app.route('/contact', methods=['GET'])
def get_contacts():
    all_contacts = Contact.query.all()  
    result = contacts_schema.dump(all_contacts)
    return jsonify(result.data)

I can simply add to celery task? as I am not sure since this is an already decorated function and have not seen example of applying celery task to an already decorated function?

i.e decorate again:

@celery.task()
@app.route('/contact', methods=['GET'])
def get_contacts():
    all_contacts = Contact.query.all()  
    result = contacts_schema.dump(all_contacts)
    return jsonify(result.data)

so that every minute it is calling the endpoint itself

forked it and you can see the changes?

https://github.com/scheung38/celery-scheduler/commit/a1a02a3cf0aa219a5eda44b5c6dadefe2f01a805

not sure why it is only firing only your original task but ignoring the new added task?

tail -f /var/log/celery/worker.log

Please specify a different user using the -u option.

User information: uid=0 euid=0 gid=0 egid=0

uid=uid, euid=euid, gid=gid, egid=egid, [2019-10-15 12:58:03,537: INFO/MainProcess] Connected to redis://0.0.0.0:6379/0 [2019-10-15 12:58:03,546: INFO/MainProcess] mingle: searching for neighbors [2019-10-15 12:58:04,565: INFO/MainProcess] mingle: all alone [2019-10-15 12:58:04,575: INFO/MainProcess] celery@e1ce888ba6f4 ready. [2019-10-15 12:59:00,018: INFO/MainProcess] Received task: app.tasks.test.print_hello[ab08405b-ff08-47ef-8af3-bd70660758cd]
[2019-10-15 12:59:00,020: INFO/ForkPoolWorker-2] app.tasks.test.print_hello[ab08405b-ff08-47ef-8af3-bd70660758cd]: Hello [2019-10-15 12:59:00,021: INFO/ForkPoolWorker-2] Task app.tasks.test.print_hello[ab08405b-ff08-47ef-8af3-bd70660758cd] succeeded in 0.000968500000454s: None

scheung38 avatar Oct 15 '19 11:10 scheung38