Giter Club home page Giter Club logo

django-user-tasks's People

Contributors

aht007 avatar awais786 avatar awaisdar001 avatar ayub-khan avatar dependabot[bot] avatar edx-requirements-bot avatar feanil avatar gabor-boros avatar iamsobanjaved avatar iloveagent57 avatar irtazaakram avatar jawayria avatar jmbowman avatar kdmccormick avatar michaelroytman avatar mraarif avatar mumarkhan999 avatar nedbat avatar neonesoft avatar robrap avatar sarina avatar timmc-edx avatar usamasadiq avatar wesmason avatar xitij2000 avatar zubairshakoorarbisoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-user-tasks's Issues

Unpin pyyaml

The version of pyyaml was pinned back in 2021 due to a swagger2rst issue that was resolved on the same day it was reported. It should be safe to unpin this now.

Support for celery message protocol 2 [TypeError('tuple indices must be integers or slices, not str')]

Currently the create_user_task signal handler always fails with TypeError('tuple indices must be integers or slices, not str') when using task message protocol version 2 (https://docs.celeryq.dev/en/stable/internals/protocol.html), which should be the celery default for many years now. The exception is catched and logged by celery and it seems to have no impact for simple use cases.

To workaround this issue the following code can be used:

from celery import signals
from user_tasks.signals import create_user_task
from myproject.celery.celery import app

signals.before_task_publish.disconnect(create_user_task)
signals.before_task_publish.connect(create_user_task_wrapper)

def create_user_task_wrapper(sender=None, body=None, **kwargs):
    return create_user_task(
        sender,
        body
        if app.conf.task_protocol == 1
        else proto2_to_proto1(body, kwargs.get("headers", {})),
    )

# Based on some old celery code:
def proto2_to_proto1(body, headers):
    args, kwargs, embed = body
    embedded = _extract_proto2_embed(**embed)
    chained = embedded.pop("chain")
    new_body = dict(
        _extract_proto2_headers(**headers), args=args, kwargs=kwargs, **embedded
    )
    if chained:
        new_body["callbacks"].append(chain(chained))
    return new_body


def _extract_proto2_headers(id, retries, eta, expires, group, timelimit, task, **_):
    return {
        "id": id,
        "task": task,
        "retries": retries,
        "eta": eta,
        "expires": expires,
        "utc": True,
        "taskset": group,
        "timelimit": timelimit,
    }


def _extract_proto2_embed(callbacks, errbacks, chain, chord, **_):
    return {
        "callbacks": callbacks or [],
        "errbacks": errbacks,
        "chain": chain,
        "chord": chord,
    }

Ditch swagger2rst dependency

Given that this package hasn't been released in 7 years or received any commits in 2 years, we should refactor our documentation builds to no longer use it. This would also unblock #291 .

Test django-user-tasks on Python 3.11

This repository is a depedency of edx-platform and needs to be upgraded to Python 3.11 before
the Readwood release is cut (mid-April).

  • Requirements are compiled with Python 3.8
  • Tests are run on Python 3.8 and 3.11
  • (Optional) Tests are also run with 3.12 and passing or 3.12 issues are ticketed.
  • Classifiers in setup.py setup.cfg or pyproject.toml indicate Python 3.11 support
  • A new version is release to PyPI
  • A PR is merged to edx-platform to use the new version

Signals not being emitted

  • django-user-tasks version: 1.3.0
  • Django version: 3.1.2
  • Python version: 3.8.1
  • Operating System: macOS 11

Description

I was trying to connect signals to the one i guess were emited when a task was created or succeeded. So I added a function in signals and tried to work out signals in django by also putting login signal to ensure signals were working.
Despite the task being conducted and finished (successfully i guess since it does what i want it to do) i have no signal emitted in any case.

I tried multiples ways and endded up adding django-debug-toolbar 3.1.1
Using this package i saw an error message in the logs
Screenshot 2020-11-16 at 15 30 35

So I looked into the create_user_task() method inside user_tasks/signals.py in the package
It looks like there is conflicts between body argument where args and kwars should be, but they seems to be in the header argument passed in **kwarg of create_user_task() under the name "argsrepr" and "kwargsrepr" (i dont know much about these names tho)

Am i doing something wrong?
Thank you,
Yoann

What I Did

my tasks.py file inside my app

class ImportTask(UserTask):
    @classmethod
    def generate_name(cls, arguments_dict):
        serie = Serie.objects.get(pk=arguments_dict['serie_id'])
        return 'Import of {}'.format(serie)

    @staticmethod
    def calculate_total_steps(arguments_dict):
        return 100


@shared_task(base=ImportTask, bind=True)
def import_csv(self, user_id, notification_key, path_file, serie_id, **kwargs):
    uploadCandles(path_file, serie_id)

my signals.py file with logged_in and out working as espected but nothing happening for the others

def user_logged_in_handler(sender, request, user, **kwargs):
    print('OUI')


def user_logged_out_handler(sender, request, user, **kwargs):
    print('NON')


def user_task_stopped_handler(**kwargs):
    print('User task stoped')


@receiver(task_success)
def task_success_handler(result, **kwargs):
    print('User task succeed')


@task_success.connect
def task_succeeded_handler(sender=None, **kwargs):
    print(sender)
    if isinstance(sender, UserTaskMixin):
        print('User task succeed')


user_logged_in.connect(user_logged_in_handler)
user_logged_out.connect(user_logged_out_handler)
user_task_stopped.connect(user_task_stopped_handler)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.