Auto Discover tasks not working in Celery4












0















I have been using Celery previously in this project, I have tasks.py file in my app directory where some tasks are defined and scheduled in the Celery.py file but when i run celery -A project worker -l info the tasks in app/tasks.py file are not getting discovered due to a reason not able to figure out.
Here is my tasks.py file



@shared_task
def fetch_interface_logs(*products):
"""
Function responsible for fetching the interface logs
"""
# print(products)
for product in products:
print(product[0])
headers = {'X-Auth-Token': ACCESS_TOKEN, "Content-Type": 'application/json'}
log_URL = BASE_URL_PROD + ACTION_URLS.get('logs').format(product[0])
interface_resp = requests.get(log_URL, headers=headers).json()

if Cloud.objects.filter(product_uid=product[0]):
base_obj = Cloud.objects.get(product_uid=product[0])

elif Cloudx.objects.filter(product_uid=product[0]):
base_obj = Cloudx.objects.get(product_uid=product[0])
interface_json = interface_resp['data']

for log in interface_json:
if log['event']:
interface = InterfaceLogs()
interface.event_name = log['event']
interface.message = log['message']
interface.resource_type = log['resource_type']
interface.log_time = arrow.get(int(log['time']) / 1000).datetime

interface.save()
# print(interface.log_time)

base_obj.interface_logs.add(interface)
base_obj.save()
return


and here is the code for the Celery.py file



from __future__ import absolute_import
import os
from celery import Celery
from celery import shared_task
from django.conf import settings
from celery.schedules import crontab
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cloud_sdn.settings')
django.setup()
app = Celery('cloud_sdn')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object(settings, namespace='CELERY')

# Load all the tasks automatically
app.autodiscover_tasks()

from app.models import Cloudx, Cloud


app.conf.beat_schedule = {

'add-cloudx_interface-logs-everyday-afternoon': {
'task': 'fetch_interface_logs',
'schedule': crontab(hour=17, minute=2),
'args': list(Cloudx.objects.all().values_list('product_uid')),

},
'add-cloud_interface-logs-everyday-afternoon': {
'task': 'fetch_interface_logs',
'schedule': crontab(hour=17, minute=12),
'args': list(Cloud.objects.all().values_list('product_uid')),

}


and here is the code for the init.py file



from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ['celery_app']


I am using redis as the broker.










share|improve this question



























    0















    I have been using Celery previously in this project, I have tasks.py file in my app directory where some tasks are defined and scheduled in the Celery.py file but when i run celery -A project worker -l info the tasks in app/tasks.py file are not getting discovered due to a reason not able to figure out.
    Here is my tasks.py file



    @shared_task
    def fetch_interface_logs(*products):
    """
    Function responsible for fetching the interface logs
    """
    # print(products)
    for product in products:
    print(product[0])
    headers = {'X-Auth-Token': ACCESS_TOKEN, "Content-Type": 'application/json'}
    log_URL = BASE_URL_PROD + ACTION_URLS.get('logs').format(product[0])
    interface_resp = requests.get(log_URL, headers=headers).json()

    if Cloud.objects.filter(product_uid=product[0]):
    base_obj = Cloud.objects.get(product_uid=product[0])

    elif Cloudx.objects.filter(product_uid=product[0]):
    base_obj = Cloudx.objects.get(product_uid=product[0])
    interface_json = interface_resp['data']

    for log in interface_json:
    if log['event']:
    interface = InterfaceLogs()
    interface.event_name = log['event']
    interface.message = log['message']
    interface.resource_type = log['resource_type']
    interface.log_time = arrow.get(int(log['time']) / 1000).datetime

    interface.save()
    # print(interface.log_time)

    base_obj.interface_logs.add(interface)
    base_obj.save()
    return


    and here is the code for the Celery.py file



    from __future__ import absolute_import
    import os
    from celery import Celery
    from celery import shared_task
    from django.conf import settings
    from celery.schedules import crontab
    import django

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cloud_sdn.settings')
    django.setup()
    app = Celery('cloud_sdn')

    # Using a string here means the worker doesn't have to serialize
    # the configuration object to child processes.
    # - namespace='CELERY' means all celery-related configuration keys
    # should have a `CELERY_` prefix.
    app.config_from_object(settings, namespace='CELERY')

    # Load all the tasks automatically
    app.autodiscover_tasks()

    from app.models import Cloudx, Cloud


    app.conf.beat_schedule = {

    'add-cloudx_interface-logs-everyday-afternoon': {
    'task': 'fetch_interface_logs',
    'schedule': crontab(hour=17, minute=2),
    'args': list(Cloudx.objects.all().values_list('product_uid')),

    },
    'add-cloud_interface-logs-everyday-afternoon': {
    'task': 'fetch_interface_logs',
    'schedule': crontab(hour=17, minute=12),
    'args': list(Cloud.objects.all().values_list('product_uid')),

    }


    and here is the code for the init.py file



    from __future__ import absolute_import, unicode_literals

    # This will make sure the app is always imported when
    # Django starts so that shared_task will use this app.
    from .celery import app as celery_app

    __all__ = ['celery_app']


    I am using redis as the broker.










    share|improve this question

























      0












      0








      0








      I have been using Celery previously in this project, I have tasks.py file in my app directory where some tasks are defined and scheduled in the Celery.py file but when i run celery -A project worker -l info the tasks in app/tasks.py file are not getting discovered due to a reason not able to figure out.
      Here is my tasks.py file



      @shared_task
      def fetch_interface_logs(*products):
      """
      Function responsible for fetching the interface logs
      """
      # print(products)
      for product in products:
      print(product[0])
      headers = {'X-Auth-Token': ACCESS_TOKEN, "Content-Type": 'application/json'}
      log_URL = BASE_URL_PROD + ACTION_URLS.get('logs').format(product[0])
      interface_resp = requests.get(log_URL, headers=headers).json()

      if Cloud.objects.filter(product_uid=product[0]):
      base_obj = Cloud.objects.get(product_uid=product[0])

      elif Cloudx.objects.filter(product_uid=product[0]):
      base_obj = Cloudx.objects.get(product_uid=product[0])
      interface_json = interface_resp['data']

      for log in interface_json:
      if log['event']:
      interface = InterfaceLogs()
      interface.event_name = log['event']
      interface.message = log['message']
      interface.resource_type = log['resource_type']
      interface.log_time = arrow.get(int(log['time']) / 1000).datetime

      interface.save()
      # print(interface.log_time)

      base_obj.interface_logs.add(interface)
      base_obj.save()
      return


      and here is the code for the Celery.py file



      from __future__ import absolute_import
      import os
      from celery import Celery
      from celery import shared_task
      from django.conf import settings
      from celery.schedules import crontab
      import django

      os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cloud_sdn.settings')
      django.setup()
      app = Celery('cloud_sdn')

      # Using a string here means the worker doesn't have to serialize
      # the configuration object to child processes.
      # - namespace='CELERY' means all celery-related configuration keys
      # should have a `CELERY_` prefix.
      app.config_from_object(settings, namespace='CELERY')

      # Load all the tasks automatically
      app.autodiscover_tasks()

      from app.models import Cloudx, Cloud


      app.conf.beat_schedule = {

      'add-cloudx_interface-logs-everyday-afternoon': {
      'task': 'fetch_interface_logs',
      'schedule': crontab(hour=17, minute=2),
      'args': list(Cloudx.objects.all().values_list('product_uid')),

      },
      'add-cloud_interface-logs-everyday-afternoon': {
      'task': 'fetch_interface_logs',
      'schedule': crontab(hour=17, minute=12),
      'args': list(Cloud.objects.all().values_list('product_uid')),

      }


      and here is the code for the init.py file



      from __future__ import absolute_import, unicode_literals

      # This will make sure the app is always imported when
      # Django starts so that shared_task will use this app.
      from .celery import app as celery_app

      __all__ = ['celery_app']


      I am using redis as the broker.










      share|improve this question














      I have been using Celery previously in this project, I have tasks.py file in my app directory where some tasks are defined and scheduled in the Celery.py file but when i run celery -A project worker -l info the tasks in app/tasks.py file are not getting discovered due to a reason not able to figure out.
      Here is my tasks.py file



      @shared_task
      def fetch_interface_logs(*products):
      """
      Function responsible for fetching the interface logs
      """
      # print(products)
      for product in products:
      print(product[0])
      headers = {'X-Auth-Token': ACCESS_TOKEN, "Content-Type": 'application/json'}
      log_URL = BASE_URL_PROD + ACTION_URLS.get('logs').format(product[0])
      interface_resp = requests.get(log_URL, headers=headers).json()

      if Cloud.objects.filter(product_uid=product[0]):
      base_obj = Cloud.objects.get(product_uid=product[0])

      elif Cloudx.objects.filter(product_uid=product[0]):
      base_obj = Cloudx.objects.get(product_uid=product[0])
      interface_json = interface_resp['data']

      for log in interface_json:
      if log['event']:
      interface = InterfaceLogs()
      interface.event_name = log['event']
      interface.message = log['message']
      interface.resource_type = log['resource_type']
      interface.log_time = arrow.get(int(log['time']) / 1000).datetime

      interface.save()
      # print(interface.log_time)

      base_obj.interface_logs.add(interface)
      base_obj.save()
      return


      and here is the code for the Celery.py file



      from __future__ import absolute_import
      import os
      from celery import Celery
      from celery import shared_task
      from django.conf import settings
      from celery.schedules import crontab
      import django

      os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cloud_sdn.settings')
      django.setup()
      app = Celery('cloud_sdn')

      # Using a string here means the worker doesn't have to serialize
      # the configuration object to child processes.
      # - namespace='CELERY' means all celery-related configuration keys
      # should have a `CELERY_` prefix.
      app.config_from_object(settings, namespace='CELERY')

      # Load all the tasks automatically
      app.autodiscover_tasks()

      from app.models import Cloudx, Cloud


      app.conf.beat_schedule = {

      'add-cloudx_interface-logs-everyday-afternoon': {
      'task': 'fetch_interface_logs',
      'schedule': crontab(hour=17, minute=2),
      'args': list(Cloudx.objects.all().values_list('product_uid')),

      },
      'add-cloud_interface-logs-everyday-afternoon': {
      'task': 'fetch_interface_logs',
      'schedule': crontab(hour=17, minute=12),
      'args': list(Cloud.objects.all().values_list('product_uid')),

      }


      and here is the code for the init.py file



      from __future__ import absolute_import, unicode_literals

      # This will make sure the app is always imported when
      # Django starts so that shared_task will use this app.
      from .celery import app as celery_app

      __all__ = ['celery_app']


      I am using redis as the broker.







      python django celery






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 13:36









      AR7AR7

      1209




      1209
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Are you starting the worker process with the correct directory? Your directory is cloud_sdn



          celery -A <directory> worker -l info





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301529%2fauto-discover-tasks-not-working-in-celery4%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Are you starting the worker process with the correct directory? Your directory is cloud_sdn



            celery -A <directory> worker -l info





            share|improve this answer




























              0














              Are you starting the worker process with the correct directory? Your directory is cloud_sdn



              celery -A <directory> worker -l info





              share|improve this answer


























                0












                0








                0







                Are you starting the worker process with the correct directory? Your directory is cloud_sdn



                celery -A <directory> worker -l info





                share|improve this answer













                Are you starting the worker process with the correct directory? Your directory is cloud_sdn



                celery -A <directory> worker -l info






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 15:37









                bdoubleubdoubleu

                617112




                617112
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301529%2fauto-discover-tasks-not-working-in-celery4%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly