TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Highlander – Stop Overlapping Python Cron Jobs

28 pointsby ccannonalmost 10 years ago

10 comments

fideloperalmost 10 years ago
Does anyone use flock? I came across it recently and believe it serves the same purpose, very useful from cron tasks:<p>man page: <a href="http:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;flock" rel="nofollow">http:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;flock</a><p>Example: <a href="https:&#x2F;&#x2F;ma.ttias.be&#x2F;prevent-cronjobs-from-overlapping-in-linux&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ma.ttias.be&#x2F;prevent-cronjobs-from-overlapping-in-lin...</a>
评论 #9710897 未加载
评论 #9712119 未加载
评论 #9710993 未加载
评论 #9711465 未加载
评论 #9711704 未加载
评论 #9712368 未加载
falcolasalmost 10 years ago
As someone who has had to write this themselves multiple times, there are a few bits that I consider to be missing:<p>1) Command line verification - is the pid owned by the same type of process as is running now? PIDs are re-used, ensure it&#x27;s the same (the creation time check helps, but it doesn&#x27;t say anything about what process wrote it).<p>2) Process Hang Detection - Has the process actually consumed any CPU ticks in the last minute?<p>3) Infinite loop detection - Is the other process stuck processing something uselessly?<p>4) Killing off stuck processes - 2 or 3 true? Behead it and continue on. Optionally do some form of alerting - stderr is probably fine.<p>Add these, and I would personally find it much more useful.
评论 #9710946 未加载
评论 #9710908 未加载
geertjalmost 10 years ago
On systemd systems there&#x27;s an easier alternative to this. You can use the per-user systemd instance (systemctl --user) to install a .timer that activates a .service file. If the .service is still running when the .timer next fires, it will not be started again. Systemd is pretty good at this kind of bookkeeping.
评论 #9711994 未加载
wc-almost 10 years ago
I&#x27;ve had a lot of sucess using a key in redis with a TTL value instead of a local PID file. Although adding redis to the picture adds a large new point of failure, I can then have a cronjob set up on multiple instances and still ensure it only runs once across all of them.<p>I&#x27;m sure there is a simpler way of doing this, how have other people solved redundantly ensuring a single cronjob runs?
评论 #9712038 未加载
ccannonalmost 10 years ago
I always encounter the problem where I write Python scripts that run on a cron job that sometimes take longer than the interval before the same cron job will run again (e.g., I have a cron that runs every hour and one run takes 2 hours to complete). In this scenario, you would want the first cron to complete before the second cron is run. What Highlander does is if it sees that your cron is already running, it immediately returns thereby skipping that cron run.
评论 #9710824 未加载
评论 #9711423 未加载
评论 #9711533 未加载
评论 #9711171 未加载
评论 #9710987 未加载
wumbernangalmost 10 years ago
Windows has by far the best solution to this since Windows Vista&#x2F;2008 server. Full instance control provided by the OS, fully scriptable with powershell, desired state configuration (like ansible), clustering, logging, fully event driven i.e. can trigger on network&#x2F;OS events with GUI, WMI, script and COM integration.<p>Genuinely wish someone knocked out something like this. systemd is part of the way there but not quite far enough.
评论 #9713137 未加载
snidealmost 10 years ago
Always bring this up anytime I see &quot;Highlander&quot; being used for a project name.<p><a href="http:&#x2F;&#x2F;blogs.msdn.com&#x2F;b&#x2F;oldnewthing&#x2F;archive&#x2F;2014&#x2F;09&#x2F;23&#x2F;10559783.aspx" rel="nofollow">http:&#x2F;&#x2F;blogs.msdn.com&#x2F;b&#x2F;oldnewthing&#x2F;archive&#x2F;2014&#x2F;09&#x2F;23&#x2F;10559...</a>
评论 #9712476 未加载
评论 #9713138 未加载
88e282102ae2e5balmost 10 years ago
Why not just use the fnctl module from the standard library?
mrfusionalmost 10 years ago
Is there a library to just parse cron strings and know when to fire?
userbinatoralmost 10 years ago
In other words, it effectively makes the process a singleton?
评论 #9713133 未加载