Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORM Huey Tables #2

Open
zN3utr4l opened this issue Sep 7, 2023 · 0 comments
Open

ORM Huey Tables #2

zN3utr4l opened this issue Sep 7, 2023 · 0 comments

Comments

@zN3utr4l
Copy link

zN3utr4l commented Sep 7, 2023

Why do Huey schedules tables and Huey tasks not auto-populating?

Here I declared the periodic and non-periodic tasks, I expected them to be recorded in the orm.

settings.py

# avryhof / huey_django_orm
INSTALLED_APPS.extend(['huey.contrib.djhuey', 'huey_django_orm'])

HUEY = {
    'huey_class': 'huey_django_orm.storage.DjangoORMHuey',
    'name': DATABASES['default']['NAME'],  # Use db name for huey.
    'results': True,  # Store return values of tasks.
    'store_none': False,  # If a task returns None, do not save to results.
    'immediate': DEBUG,  # If DEBUG=True, run synchronously.    (FALSE)
    'utc': True,  # Use UTC for all times internally.
    'compression': True, # Compress tasks and result data.
    'use_zlib': True, # Use zlib for compression instead of gzip.
    'consumer': {
        'workers': 4,
        'worker_type': 'thread',
        'initial_delay': 0.1,  # Smallest polling interval, same as -d.
        'backoff': 1,  # Exponential backoff using this rate, -b.
        'max_delay': 5,  # Max possible polling interval, -m.
        'scheduler_interval': 1,  # Check schedule every second, -s.
        'periodic': True,  # Enable crontab feature.
        'check_worker_health': True,  # Enable worker health checks.
        'health_check_interval': 1,  # Check worker health every second.
    },
}

tasks.py

from test_app.models import Person
from datetime import datetime
from huey import crontab
from huey.contrib.djhuey import db_periodic_task, db_task, lock_task

@db_periodic_task(crontab())
@lock_task('create-lock')  # Goes *after* the task decorator.
def create():
    print(f"Executing create ...")
    name = datetime.now().strftime('%Y-%m-%d %H:%M')
    obj = Person.objects.create(name=name)

    # Generate database backup. Since this may take longer than an
    # hour, we want to ensure that it is not run concurrently.
    with lock_task('get-lock'):
        get(name)
    print(f"Finish create for object {obj.name} ...")

@db_task()
def get(name):
    print(f"Executing get ...")
    obj = Person.objects.get(name=name)
    print(f"Finish get for object {obj.name} ...")

@db_periodic_task(crontab())
@lock_task('count-lock')  # Goes *after* the task decorator.
def count():
    print(f"Executing count ...")
    objs = Person.objects.count()
    print(f"Finish count {objs} ...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant