Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
331 stars 77 forks source link

rundramatiq should search for `dramatiq` in the `Scripts` directory on Windows #49

Closed AgentDaun closed 3 years ago

AgentDaun commented 4 years ago

settings.py:

"""
Django settings for permissions_test project.

Generated by 'django-admin startproject' using Django 2.2.4.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import redis
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$t&u7oces91v6-4v0bi4ntp$z+m#ih+$tr+avjs3p#l3ru(5d4'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_dramatiq',
    'users',
    'profiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'permissions_test.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'permissions_test.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
        }

        # Password validation
        # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

DRAMATIQ_REDIS_URL = os.getenv("REDIS_URL", "redis://127.0.0.1:6379/0")
DRAMATIQ_BROKER = {
    "BROKER": "dramatiq.brokers.redis.RedisBroker",
    "OPTIONS": {
        "connection_pool": redis.ConnectionPool.from_url(DRAMATIQ_REDIS_URL),
    },
    "MIDDLEWARE": [
        "dramatiq.middleware.AgeLimit",
        "dramatiq.middleware.TimeLimit",
        "dramatiq.middleware.Retries",
        "django_dramatiq.middleware.AdminMiddleware",
        "django_dramatiq.middleware.DbConnectionsMiddleware",
    ]
}

DRAMATIQ_RESULT_BACKEND = {
    "BACKEND": "dramatiq.results.backends.redis.RedisBackend",
    "BACKEND_OPTIONS": {
        "url": "redis://localhost:6379",
    },
    "MIDDLEWARE_OPTIONS": {
        "result_ttl": 60000
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
            },
            {
                'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
                },
                {
                    'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
                    },
                    ]

# Кэш
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
        }
    }
}

# Храним сессию в Cache
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
AUTH_USER_MODEL = 'users.User'

I've installed "django_dramatiq, dramatiq, watch, Redis" in /admin exists all tasks that i created

Bogdanp commented 4 years ago

Sorry, but this is too broad for me to help. You're probably not in the right virtual environment, or running the wrong python executable.

watsonhaw5566 commented 4 years ago

@AgentDaun unintall your django_dramitq and reinstall it. That question is you virualenv promble, i meet it once

ghost commented 4 years ago

Hey there! I have the same issue and I think it is because I don't use a virtualenv. When I have a closer look at the stack trace the problem is that the dramatic executable is searched inside the python bin directory. If you use Anaconda (like me) then it is located inside the %PythonRoot%/Scripts folder and this is why the error says "No such file or directory".

To make it find the right executable you can replace the function "_resolve_executable" in the folder %PythonRoot%/lib/site-packages/django_dramatiq/management/commands/rundramatiq.py with the following:

def _resolve_executable(self, exec_name):
    bin_dir = os.path.dirname(sys.executable)
    bin_dir = os.path.join(bin_dir, "Scripts")
    if bin_dir:
        return os.path.join(bin_dir, exec_name)
    return exec_name

I hope this helps!

magraeber commented 3 years ago

I get the same error using a Windows Docker Container with base image Python:3.7. It works perfectly with Linux Containers.

Getting Windows and Linux support was the main reason why I would like to switch from Celery to Dramatiq. Is there any chance to get this fixed? Search in both directories?

Bogdanp commented 3 years ago

@magraeber Searching both directories seems reasonable, but I don't have a Windows machine to test this. If anyone is willing to do the work, I'll happily merge such a change.

magraeber commented 3 years ago

@Bogdanp Perfect, I will work on that and prepare a pull request.

Bogdanp commented 3 years ago

Closed in 4c70775bbdd7b4a6844afeec48ddb58d3bb7275d