Django Apscheduler

Has anyone used Django Apscheduler and if so what is your opinion?

If you’ve already got background tasks that you are running from Django, you’re already using Celery. And if these tasks are always going to run on a schedule, you have cron.

I don’t see the benefit of adding another process scheduler when you already have two other well-established options.

I do not have any task that I have started. I just need to run a task to check a mailbox folder and download messages every x time.

So does Django have this or is it python/cron?

I’d suggest setting that up as a cron job. Or, if you know it’s going to run “forever”, I’d create it as a persistent process and have it sleep for the desired interval. (That saves the overhead of launching a new process on a periodic basis.)

So I would need to create a .py for the code to run and then use cron to schedule. Right now I just do crtl-S and it runs from my view.

I would have to create this on the linode server correct?

This is the code I want to run.

with MailBox(x').login('x', 'x', initial_folder='INBOX') as mailbox:
    for msg in mailbox.fetch():
        if 'x' in msg.from_:
            sender = CustomUser.objects.filter(alias_email=msg.from_).get()
            recipient = CustomUser.objects.filter([0]).get()
            message = msg.text
        elif msg.from_ in CustomUser.objects.all().values_list('email', flat=True):
            sender = CustomUser.objects.filter(email=msg.from_).get()
            msg_a = msg.text.find('\nOn ')
            msg_b = msg.text[:msg_a]
            msg_c = re.sub(r'(\n\n.*$)', '', msg_b)
            msg_d = re.sub(r'\n', ' ', msg_c).split()
            message = ''
            for word in msg_d:
                message = message + word + ' '
            mailbox.move([msg.uid], 'Trash')


You would likely do that, but it’s not truly necessary. It depends upon what you’re going to do with that data. If you’re writing those messages to the database, you can run that code on any system having access to both the mail server and the database.

So the process is that the message is brought in and then processed to get the new message only. It then gets scrubbed for profanity and other items and then is written to the database with the sender id, recipient id, orginal msg, cleaned msg, and date/time

I have a mail-in-a-box email server that is with linode so should I just put the messages the db from there and then process in django? The .py would need to have access to the CustomUser model.

That’s something that only you can address in the context of the information available to you. Without having a lot more details about your target environment, we really wouldn’t be able to offer concrete advice.

Two ways to look at this - if you want to use the Django ORM, you would create your code as a custom management command. Or, you could bypass all the Django libraries and write code that works with the database directly using SQL. That’s your choice to make.

Can you give me the step how to schedule a jab in django using Django_apsheduler , I am unable show my jobs inside admin panel
Please resolve my doubt.

I’m sorry, I don’t use django-apscheduler nor do I recommend it being used. See the remainder of this thread for other options.