Skip to content

[QUESTION] How to add API calls? #3

@scheung38

Description

@scheung38

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?

scheung38@a1a02a3

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions