Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How to add API calls? #3

Open
scheung38 opened this issue Oct 15, 2019 · 0 comments
Open

[QUESTION] How to add API calls? #3

scheung38 opened this issue Oct 15, 2019 · 0 comments

Comments

@scheung38
Copy link

scheung38 commented Oct 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant