How to Create a Simple Alert for Long-Running Jobs
If you are tired of executing long-running commands and having to wait idly for the result, you can set up a simple alert system to get notified when the task is finished.
Whether you are running a long Machine Learning training task, analyzing a load of data, or executing a long simulation, this alert enables you to step away from the computer and get notified when to come back.
In this article, I show you how to install a simple Python script that will send you a message on a Slack channel, Discord channel, or anything else. I use this often in my work and I hope it will be useful to you too.
This guide is created for Linux, but can also be installed for Mac or Windows as long as you can get Python.
The alert works by using the knockknock library in Python. The main
alert file in the repository is only 17 lines of code!
Set up the alert in 6 easy steps
1. Clone the repository anywhere in your computer
git clone https://github.com/justinsj/alert-git
2. Install the requirements
sudo pip install setuptools-rust
python -m pip install — upgrade pip
python -m pip install -r requirements.txt
3. Set up your Slack webhook URL.
To do this, check out https://api.slack.com/messaging/webhooks.
4. Change the SLACK_WEBHOOK_URL and DEFAULT_SLACK_CHANNEL in alert.
In the file
alert , update the variables to your webhook URL and default channel.
SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/T0JQQQQQQ/B0JQQQQQQ/XXXXXXXXXXXXXXXXXXXXXXXX'
DEFAULT_SLACK_CHANNEL = 'your-slack-channel'
5. Ensure that the alert code is executable
chmod +x alert
6. Copy the file to an easily accessible location like ~/alert.
cp alert ~/alert
Now you can use ~/alert with any long task!
For example, from any folder, you can do:
~/some-folder$ python some_long_task.py && ~/alert
Finally, you can set a custom message after the
In this article, I have written about a simple alert system that I personally use often and install in almost every machine I work with.
If you enjoyed this article or learned something from it, I would appreciate your clap!
If you also have anything to suggest, let me know in the comments or message me on LinkedIn!