Skip to content

Commit

Permalink
celeray task
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Sep 15, 2024
1 parent 1706c34 commit d1705a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
13 changes: 3 additions & 10 deletions say/api/need_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion say/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 9 additions & 7 deletions say/tasks/update_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit d1705a3

Please sign in to comment.