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

Question: how to show the running task on the django-admin with redis as broker #270

Closed
karimone opened this issue Nov 8, 2017 · 5 comments

Comments

@karimone
Copy link

karimone commented Nov 8, 2017

Hello, I'm not an expert on redis, but I would like to know how to get a sense of what is actually on process on redis.

I had a look at django-redisboard but I have no idea how to read the information on redis to get the current running tasks situation.

I have already a custom page in the django-admin to show some informations about the app, I can easily add some infos about the running tasks, but I don't know how to get those data.

Do you have any example code to get what I need from redis using the python client?

Thank you!

@Eagllus
Copy link
Collaborator

Eagllus commented Nov 9, 2017

@karimone I'm not a 100% I understand what you are looking for.
But Redis would be the queue for your Django-Q Cluster.
with django-redisboard (looking at the screenshots) you can check a lot more then just the current running task.

From the screenshots it seems you can check server config, Get a list of the key space and Get a list of items within a key.

I'm not an expert on redis

I'll try to explain the 3 points.

  • check server config Kinda self explanatory.
  • Get a list of the key space You can create multiple key spaces (Queues or Categories what ever you like to name them)
  • Get a list of items within a key This is the list of items within the selected queue (I think this is the part your looking for)

@Koed00 created a nice Redis broker in Django-Q that already supports a few features for you (that you can also use yourself)

@karimone
Copy link
Author

karimone commented Nov 9, 2017

I think I explained my self very badly.
What I need is see the status of the running tasks from the django admin. At the moment only successful and failed tasks are available. Based on what I see is sufficient get the list of keys, not sure where I can get the details of the tasks, but I'll have a more detailed look tomorrow. Thank you for your answer

@karimone
Copy link
Author

Reading the docs, I see we have 2 signals available. The interesting one is Before executing a task. This signal could be used to create a record about the task current on execution.

The problem is the end of the task. The async use the hook parameter, I wonder if is possible to have a signal about the task ending or I can just check the post_save on a Task.

In other words, I would like to get the same feature you get using the django orm as a broker with the Queued Task admin page.

At the moment I could use just the django orm, but I'm not really aware about the downsize on using it instead of redis

@Eagllus
Copy link
Collaborator

Eagllus commented Nov 10, 2017

@karimone you can use the django orm without any problems. (using it in production myself)
If you run many tasks the load to you database server does increase quite a bit but it also removes the need for Redis.

You can easily create a record of the current task with the django_q.signals.pre_execute and after that you can use the same id of the task in a signal post_save to remove it from your database.
Or you pass the task a hook that's called after the save.

@receiver(post_save, sender=Task)
def call_hook(sender, instance, **kwargs):
if instance.hook:
f = instance.hook
if not callable(f):
try:
module, func = f.rsplit('.', 1)
m = importlib.import_module(module)
f = getattr(m, func)
except (ValueError, ImportError, AttributeError):
logger.error(_('malformed return hook \'{}\' for [{}]').format(instance.hook, instance.name))
return
try:
f(instance)
except Exception as e:
logger.error(_('return hook {} failed on [{}] because {}').format(instance.hook, instance.name, e))

@karimone
Copy link
Author

At the end I decided to use the django orm and everything it's good and fine :-) Thank you

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

2 participants