From d1705a360ed33d8b1bb281e9d91804670e308439 Mon Sep 17 00:00:00 2001 From: ehsang Date: Sun, 15 Sep 2024 19:25:04 +0330 Subject: [PATCH] celeray task --- say/api/need_api.py | 13 +++---------- say/celery.py | 2 +- say/tasks/update_needs.py | 16 +++++++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/say/api/need_api.py b/say/api/need_api.py index 42062088..71ea8aec 100644 --- a/say/api/need_api.py +++ b/say/api/need_api.py @@ -334,12 +334,8 @@ def patch(self, need_id): need.link = new_link session.flush() - if "Protein" in need.name_translations['en'] or "Dairy" in need.name_translations['en']: - print("Fresh Products") - update_need.delay(need.id, True) - else: - print("Not Fresh Products") - update_need.delay(need.id, False) + update_need.delay(need.id) + if 'affiliateLinkUrl' in request.form.keys(): need.affiliateLinkUrl = request.form['affiliateLinkUrl'] @@ -696,10 +692,7 @@ def post(self): if new_need.link: from say.tasks import update_need - if "Protein" in name_translations['en'] or "Dairy" in name_translations['en']: - update_need.delay(new_need.id, True) - else: - update_need.delay(new_need.id, False) + update_need.delay(new_need.id) return new_need diff --git a/say/celery.py b/say/celery.py index ecf50689..590c2f8b 100644 --- a/say/celery.py +++ b/say/celery.py @@ -23,7 +23,7 @@ }, 'update-needs': { 'task': 'say.tasks.update_needs.update_needs', - 'schedule': crontab(minute=30, hour='0,4,8,12,16,19'), + 'schedule': crontab(minute=00, hour='0,4,8,12,16,20'), }, 'report_to_family': { 'task': 'say.tasks.report_to_family.report_to_families', diff --git a/say/tasks/update_needs.py b/say/tasks/update_needs.py index e8d4f7a0..5a832061 100644 --- a/say/tasks/update_needs.py +++ b/say/tasks/update_needs.py @@ -23,12 +23,7 @@ def update_needs(self): t = [] for need in needs: t.append(need.id) - if "Protein" in need.name_translations['en'] or "Dairy" in need.name_translations['en']: - print("Fresh Products") - update_need.delay(need.id, True) - else: - print("Not Fresh Products") - update_need.delay(need.id, False) + update_need.delay(need.id) return t @@ -41,11 +36,18 @@ def update_needs(self): retry_kwargs={'max_retries': 1}, queue='slow', ) -def update_need(self, need_id, fresh, force=False): +def update_need(self, need_id, force=False): from say.models.need_model import Need sleep(5) need = self.session.query(Need).get(need_id) + if "fresh" in need.link: + fresh= True + print("Fresh Product: ", need.id) + else: + fresh= False + print("Not Fresh Product: ", need.id) + data = need.update(fresh, force=force) safe_commit(self.session)