I've got an idea for a module and I'd love some feedback.
I'm a sysadmin and I write a lot of perl to help me run my systems. One thing I seem to need a lot is something that knows if it just did something.
For example, a script that might page me would be nice if it new it had just paged me. Then it could limit how often it paged me.
In simple little scripts that run often, perhaps via cron, you need something persistent outside of the script to keep track of that, and that's what my module would handle.
Here's an example of how it might work in semi-pseudo code. Pretend it runs every minute in cron:
... use TimeLock; my $timelock = TimeLock->new('/tmp/foo_timelock'); if ( something_really_bad() ) { my $message = "Something Really Bad just happened..."; if ( !$timelock->locked($message) ) { page_me($message); $timelock->set_lock($message,600); } }
Creates new TimeLock object and uses $filename as the persistent store.
$key is any string you like that identifies the action you're locking. $span is how long you want the lock to sit in place.
Returns true if set_lock($key,$span) was called fewer or equal to $span seconds ago.
Right now my idea for the implementation is to use a GDBM file to store the keys and spans. The actual key in the GDBM file might be a hash of the real key. Hashing might be too much of a slow-down. The span would be stored as time()+$span. I'm thinking I'd have a permanent key in the store that noted how often the store was cleaned of expired keys. When you access the store, the accessor might read that to decide if it should spawn a child to clean up any old expired data.
TimeLock is the only idea I've had for a name, so any better name ideas would be great.
Otherwise, any comments on the idea would also be great.
This is aimed at small systems maintenance scripts and it should be highly portable.
Algorithm::FloodControlUpdate: It already exists! Algorithm::FloodControl. Thanks for the help everyone. I don't think I would have found Algorithm::FloodControl if it weren't for these conversations.</P.
In reply to RFC: Time Lock Module Idea? by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |