> How would a cron know by looking at a text
> file or DB entry when it was supposed to
> send the mail?

The cron doesn't look at the DB... your scheduler script does (which is
started by cron).  The scheduler might do something like this:

1. open the database
2. search for records with a "to_send_date" that
  has past AND has not yet been sent.
3. loop over each search result, sending the mail
  and marking it as having been sent.
4. close the database
5. the script exits.

Cron would run this script every hour.

I have done this in the past for eCard systems and such, but none of it is
code that I can pass around.  It's hard to come up with a sample as well
because it depends on the technologies you want to use for your schedule
storage.  I recommend a real database (MySQL, Oracle, etc) as opposed to a
text or csv file... but it all depends on what your client it running.

Using a DB to do this is straight-forward since all you need to do is query
the DB that have a "send_date" column that is older than the current time,
and send those records.  If you use a text file you need to worry about
parsing, updating, locking, and everything else the DB engine handles for
you.

Rob


-----Original Message-----
From: Scot Robnett [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 03, 2003 2:39 PM
To: Hanson, Rob; [EMAIL PROTECTED]
Subject: RE: Running process in background?


I sort of follow you, but I'm not exactly sure how to implement something
like that. How would a cron know by looking at a text file or DB entry when
it was supposed to send the mail? Has anyone done anything like this, and
are there code samples available somewhere that I can review?

-----
Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]



-----Original Message-----
From: Hanson, Rob [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 03, 2003 1:20 PM
To: 'Scot Robnett'; [EMAIL PROTECTED]
Subject: RE: Running process in background?


Your first solution is prone to memory leaks and your second is just a pain
(INHO).

> Is there a third alternative?

Sure.  Create a cron that runs every hour (or less) and checks for scheduled
mail to send.  All you need to do is have some sort of persistant storage
(file or preferably a DB) to store your schedule.  Each hour a cron launches
your send script which queries the schedule (On Oracle: Select * from
schedule where send_time > Sysdate), then iterates through each sending a
mail.

Rob

-----Original Message-----
From: Scot Robnett [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 03, 2003 1:50 PM
To: [EMAIL PROTECTED]
Subject: Running process in background?


I'm setting up a mailing subroutine for one of my customers that will send
mail based upon a delay of X amount of hours (selected via web form).

If I use something like:

  sub send_on_schedule {
   my $hours = $q->param('delay');
   my $sleeptime = $hours * 3600; # how many seconds?
   my @addresses = ('[EMAIL PROTECTED]','[EMAIL PROTECTED]'); # from a DB
   sleep $sleeptime;
   foreach my $address(@addresses) {
    some_mail_sending_routine($address);
   }
  }

then my script/process could technically be running for 24 hours before
sending the mail. I want to allow the delay, but I don't think it's a good
idea for that process to be running the entire time.

I gave some thought to using a cron job, but basically what would have to
happen is that in every instance, I'd have to create a crontab, run the
cron, then destroy it again. Still, this might be better.

Is there a third alternative? Suggestions please? Thanks.

-----
Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to