Intro

Alright. So I am setting up this web site where any two users could sort-of interact with each other at any given time. Let's name any pair of users just Alice and Bob. :-)

Now, one of the interactions consists of Alice filling in a report about an event and then requiring Bob to either confirm or deny that event, within 24 hours. If he doesn't respond, it is implied that he agrees with the report and confirms it.

If the event is confirmed, then some DB changes need to be made and a bunch of e-mails need to be sent around.

If Bob objects to the report or denies the event (same thing), only a small DB change is needed (an Objection flag needs to be set) and nothing else is required until an administrator sets out to review the case.

What I need

So, basically, what I need is this:

When Alice files the report, a task needs to be scheduled. The task should be executed either after 24 hours or whenever Bob confirms the report, whichever comes first. But the task shouldn't be executed when Bob makes an objection.

The most logical thing, it seems, is that the scheduled task itself checks whether it still needs to be executed. So, before the scheduled tasks does anything, it simply checks the DB. Has Bob confirmed or objected? Don't do anything. Has Bob not responded? Execute the task.

A problem

Unfortunately, I lack access to cron or at like services, so I'll need to build something myself. The easiest thing to do, it'd seem, would be to make a Scheduler like module that checks for queued tasks on every hit (simply use MyScheduler; in every script of the website). Easy enough, but maybe a bit heavy resource-wise. Another problem I see would be when nobody checks the website for more than 24 hours. The MyScheduler won't be activated and scheduled tasks won't run in time. :-(

So I could start a background process that'll sleep 60*60*24;, check whether it still needs to run, and perform its job if necessery, but that will soon get messy when lots of users start to file reports.

And finally: my question

What better solutions are out there?

I have been given a few answers in the CB, which I will include here for completeness' sake. Please, comment on them or provide additional answers.

[tye] Best option is probably a long-running daemon that checks for stuff to do on a reasonable schedule and also does exec($^X,$0,@ARGV) every day or few

[muba] hm. I like the daemon idea. I should basically start it just with ./myschedulerd &, right?

[ysth] nohup. or even Net::Daemon [...] no, it's not N::D I was thinking of.[...] maybe Daemon::Generic


In reply to Scheduled tasks from CGI website. But no cron or at. by muba

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.