Schedule Multiple Emails Python 3 - python-3.x

I am using SMTPlib package to create multiple emails in one application and the code works fine to send email. But, I want to be able to schedule each email to be sent at different day/time.
For instance, one at 9AM Monday and another at 12 Noon Wed.
I looked at some slightly different questions and answers on SO, where the recommendation is use of Crontab. However, Crontab is only helpful to schedule the entire application not individual parts of the application.
Sched package is also available, but I am not familiar with it and hence not sure, if I can efficiently use this for my use case.
Appreciate your thoughts

Maybe you should create separate python file/process responsible only for sending emails. You can run it when you need to queue/send emails and you might just kill it afterwards.

Related

What are some options to handle a scheduled task based on a given datetime in the database?

Im using react and node.js
Im trying to build a site that has multiple countdown timers where an user can join in before it hits 0. These countdown timers are displayed based on a pre-set datetime value in the database. When the time hits 0 (datetime is reached) i need that specific timer to become disabled and trigger a function to send out something (like an email) to all those that entered.
I tried looking around but im not sure whats best used for this (must be reliable). I saw cron-scheduler, cron, cron-node etc but maybe im looking at it from the wrong angle... The only requirements are that it needs to trigger at the given datetime and send out a message (like an email, seperately).
Usually timers run for a couple days to maximum a week
We use Django and Celery for our backend serving our APIs. For scheduled tasked we use django-celery-beat. We are running Postgresql for the database and django-celery-beat includes all of the models for the tasks and includes cron.

Linux doesn't execute scheduled job later than schulded time

I am beginner with Linux cron job.
Requirement:
Record attendance of employee. Every dayat 10 AM a Jar should execute and asks to login to record his/her presence.
Cron Job
I have created a cron job and placed at /etc/cron.d/ and has below line.
0 10 * * * /home/user/Documents/attendance.sh
If system get started before 10 AM then a login screen UI comes but if user comes late and start system after 10 AM then it doesn't show login screen UI.
So it should execute JAR even though user login after 10 AM.
Also, pleaes let me know if there is another way to achieve this goal.
Please guide.
Thanks,
Ankur
A couple of alternatives occur to me.
1 If you'd like to have attendance.sh run for every user at login, you could add it to the system-wide login shell rc file, probably /etc/profile.
2 If it's available, you could use anacron, which is well suited for systems that are not running all the time. You could schedule attendance.sh to run daily at a particular time after login.
These alternatives will behave differently. 1 will run at each login, so several times a day or only once in several days, depending upon whether the user logs in and out daily, several times daily or stays logged in when they leave work. 2 will run every day that the user is logged in (assuming that they stay logged in at least as long as the delay you specify).
If your requirements are more exacting, say "run at 10 for all logged in users, otherwise run when a late user logs in". You could make something work, but doing so would require some extra work.
Added following questioners comment
As I alluded to in my discussion of how 1 & 2 differ there can be problems with 1 if the user does not just log in at the start of their work day and log out at it's end. It sounds to me as if what you are really after is an application that is tied into the window manager. I am not experienced with triggering scripts with window manager events, but surely it's possible to do so, e.g. Run script on screen lock/unlock. You may have to do some research depending upon your needs and the sort of systems that you have. One thing to keep in mind is that a solution that works for the user who doesn't log out every day may backfire on those who log out several times a day. Solution 2 may be the best of the easy straightforward solutions for your problem, but you may need something more elaborate to handle edge cases and where (perhaps) employee performance is being monitored.
You can make the script run hourly. Script checks the time, if it's 10 or later, it checks if the user logged in today, and if not asks him to login. So you can record the login hour too.
Edit: You can put your script in /etc/cron.hourly

Is Cron the right option for this?

I am trying to create a script that watches my college time table and registers them for a class when it is open. Kind of like an Ebay auction sniper. I was wondering if cron is the right tool for this. I need to be able to run the script for every user. The user will enter their username and password and the script will query the timetable.
Looking for some advice on if cron is the tool or if there are other tools out there.
cron runs a particular program or script at a specified time. For example, if you wanted a report compiled and e-mailed every day at 2 a.m., that would be a cron job.
In this sense, cron has a timetable, but I am not sure that it is the sort of timetable of which you are thinking.
From a system-design perspective, the clean way to achieve the effect you want naturally would be to let the students' class requests join a queue, then to have the college's registrar's own computer take requests from the queue as seats became available. However, I assume from your Ebay reference that this is not possible in your case.

How to run Node.js jobs routines

Right now I have a weekly email job that works by first checking a last_email_sent timestamp against the current time, it then uses setTimeout to schedule a routine that is exactly a week from the last_email_sent timestamp. If the process ever restarts, the setTimeout would be queued again but the interval would of course be smaller. This works for a weekly email job, but is there a better way to handle jobs in node.js? Maybe there's a module out there that can let me manage my jobs that I'm not aware of.
There's a handy module in npmjs.org called node-cron.
It'll give you more flexibility.
Many of the modules listed in the node.js wiki under "Message Queues" will help with this type of system. Being a TJ Holowaychuck fanboy, I myself would probably first look at Kue.

As a user, I want a status bar (or similar) to notify me that a job is working when using a Wx.Python gui app

Can someone recommend a straight forward way of adding some type of graphical notification (status bar, spinning clocks, etc...) to my wx.Python gui application? Currently, it searches logs on a server for unique strings, and often times takes upwards to 3-4 minutes to complete. However, it would be convenient to have some type of display letting a user know that the status of the job towards finishing/completion. If I added a feature like this, I'm not sure, but I'm afraid I may have to look at using threads ... and I'm a complete newbie to Python? Any help and direction will be appreciated.
Yes, you'd need to use threads or queues or something similar. Fortunately, there are some excellent examples here: http://wiki.wxpython.org/LongRunningTasks and this tutorial I wrote is pretty straight-forward too: http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/
Using threads isn't that hard. Basically you put the long running part in the thread and every so often, you send a status update to your GUI using a thread-safe method, like wx.PostEvent or wx.CallAfter. Then you can update your statusbar or a progress bar or whatever you're using.

Resources