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); } }

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::FloodControl

Update: 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.