I need to call the celery task (in tasks.py) with models.py, the only problem is that tasks.py imports models.py, so I cannot import tasks.py from models.py.
Is there a way to invoke the celery task by simply using its name, without having to import it? A similar thing is implemented for ForeignKey fields for the same reason (preventing cyclic import).
Yes there is.
You can use:
from celery.execute import send_task send_task('my_task', [], kwargs)
Make sure the task function has a name:
from celery import task @task(name='my_task') def my_task(): ...
Hope this helps!
In celery 3+:
from celery import Celery app = Celery() app.send_task('my_task', [], kwargs)
Source: https://habr.com/ru/post/955462/More articles:CMake: avoid header and source files Visual Studio Filters and put cpp and h files at the root of the solution - cmakeHow to remove GIT version control from an Xcode 5 project - gitWhat are JSDoc @type curly braces for? - javascriptDeploying Clojure / Clojurescript in production - clojureJava Atomic Variable set () vs compareAndSet () - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/955463/is-it-possible-to-provide-a-list-of-custom-stopwords-to-rtexttools-package&usg=ALkJrhi-TQwDmzvfeZBihxrTzmEUBPGnPgProblem with UITabBar button, TabBar button becomes un clickable - xcodeHow to use HTML5 to check date range? - javascriptSplit HTML pages into horizontal sections without vertical scrollbars - htmlWhy is Stripe.com return error (402) Payment required? - apiAll Articles