Scheduling task from Django admin Panel - django

I want to schedule a task in Django which would run at a paticular time every day.I am thinking of using celery to schedule the tasks so I wanted to know is there anyway through celery-beat I could execute the task through admin panel that is make it active or inactive and give the time at which I want to execute task through my admin site.Instead of writing this in my code
crontab(day_of_week="0,6", hour="0,12", minute=15)
I want to pass it through my admin panel so that in future if I want to execute my task at some other time I could change it directly through admin panel instead of changing my code.

You will need to implement that on your own or use a third-party project. Luckily, someone already created something like that:
https://django-celery-beat.readthedocs.io/
This extension enables you to store the periodic task schedule in the
database.
The periodic tasks can be managed from the Django Admin interface,
where you can create, edit and delete periodic tasks and how often
they should run.

Related

Can I edit cronjobs using my Django application?

I am creating a Django application for school project. I want to schedule jobs (every (work)day on 9:00 and 17:00).
I am trying to do it with Celery right now, but I stuck very hard on it, and as the deadline is in sight, I want to use alternative options: just a cronjob. I think just the cronjob works fine, but the user should be able to edit the times of the cronjobs using the Django web application (so not logging in to SSH, edit the crontab manually).
Is this possible? Can't find anything about it on the internet.
You need django-celery-beat plugin that adds new models to the django admin named "Periodic tasks" where you can manage cron schedule for your tasks.
As an alternate, if you really do not want to run a background tasks, you can create django management commands and use a library like python-crontab to add/modify/remove cron jobs in the system.

Execute function at special time using Django

I write task manager, and i want to create bot, which must send message to user (maybe user's email or social account).
I want to user can be able choose task and set time, when bot should send message to him.
My proble is that I don't know what i can user for it, I use django framework, and now i think that celery can help me with it.
Celery might be a bit heavy to start with.
You can try the django_cron to schedule your email tasks or other cron jobs that need to run at a specific time.
It's quite easy to set up following its documentation.

Dynamic Celery Scheduling

Using Django & Celery is it possible to add/modify the scheduler dynamically from code and have it update in real time.
I noticed the /admin/djcelery/periodictask/add/ option in the admin panel to add periodic tasks but how can this be done from my Django views?
Ideally I'd be able to add multiple period tasks with the same task but different arguments
Just create a periodictask object.
from djcelery.models import PeriodicTask
PeriodicTask.objects.create(...)
You may have problems because you may need to restart celerybeat.. to reload all periodic tasks.

User management of periodic tasks in django celery app

Django celery (djcelery) is considered obselete these days, but to me it seems to offer some unique features still. For example with djcelery one can allow the user to add a periodic task easily by creating an instance of their PeriodicTask. Is this the best way to do this? If not how else could I allow users to manage periodic tasks in a django+celery app?
(Just to be clear I know I can hardcode periodic tasks in settings.py celery beat schedule with djcelery, but I'm talking about user management of periodic tasks, creating/updating/listing/deleting, via the admin or some mini app which interfaces a model like djcelery's PeriodicTask model)

Interacting with a program in the background of Django

I have a program that classifies text and would like to make it interactive with a user on the front-end of my django site. The problem is it takes 20 seconds for the program to load the training set and get going, and that's not feasible every time someone enters input.
Instead, I'd like Django to load the program once when the server starts, and have all user input interact with it via a view.
I looked at launching subprocesses, but if I'm not mistaken, a subprocess would only be launched when a view is called and that is undesirable for this.
Any ideas?
Thanks.
It's possible that Celery would be appropriate here. There is Django integration available with django-celery.
As Jim noticed celery is one of the best options you have for asynchronus task management, but if you want to avoid celery & its dependecies overhead you could just add a status field on the model the process takes place (e.g. text_processed boolean field with default=False) and create an application management command which would handle the process of the created db entries.
Add the command on a cron and you are done.