Post #318,483
12/12/09 2:29:39 PM
|
Suggestions on how to structure something
I'm working on my autoresponder, and need some feedback on how to structure it.
Basic componenents/tables are:
subscriber -- self-explanatory
responder -- A mailing list. Users subscribe and get both scheduled posts (send per-user $x days after signup) and immediate posts (send now to all current members).
message -- A scheduled post.
mail -- An immediate post. (I'm not convinced this should be separate from "message". The only thing different is how it's scheduled.)
When a new "mail" is created, it populates a queue of userID/mailID pairs.
The subscriber table contains a comma-delimited list of which "message"s a subscriber has received.
Once per hour, a script runs that first does a query to determine what users should receive a message during the current run and works through those, then starts working through the mail queue. (There is a per-hour cap to comply with host limits, so either process may not send everything in one run.)
The whole system is built procedurally, no classes in sight. And lots of copy-paste -- I'm talking hundreds of lines at a time here -- where there could at least be functions.
I'm refactoring it, and I'm not sure where to hang some of the methods/properties, primarily around formatting and sending the mail. I'm going to create a "queue" class -- I'm thinking static, not an instantiated object -- to insert to and process the queue. But should formatting and sending the message be a method of the "queue" class or the "message" class?
Second, should I make the queue class static or instantiate the object?
--
Drew
|
Post #318,489
12/12/09 7:59:00 PM
|
Re: Suggestions on how to structure something
majordomo? /me flees
|
Post #318,490
12/12/09 9:39:04 PM
|
Har-dee-har
If I wanted something that sent the same message all at once to everyone currently on a list, I could use my host's built-in list feature. I need the scheduling.
--
Drew
|
Post #318,493
12/12/09 9:51:16 PM
|
Re: Suggestions on how to structure something
Messages format themselves (or have an associated formatter). Queues send messages.
As to the other question, who cares. If there's only going to be one, use a Singleton or static. If you might have different queues (immediate vs. scheduled, maybe, or high vs. low priority, whatever) than instantiate one for each.
Did you look for any open source utilities that do this already?
Regards, -scott Welcome to Rivendell, Mr. Anderson.
|
Post #318,494
12/13/09 12:30:03 AM
|
I'm using one
There are a bunch of options to pay for a hosted solution, and several pricey shrink-wrap packages. But this doesn't seem to have attracted much OS love, probably because it's viewed as spam tools by most people.
The one I'm using already does 95% of what I want, but the last 5% is a bitch to add because it's so badly structured. And the bug I'm trying to trace is somewhere in the middle of a 620-line file with only two functions in it -- the ones I added for logging, and managing a lock file. I suspect about 200-250 lines of it will be redundant once I refactor it.
--
Drew
|
Post #318,496
12/13/09 12:47:14 AM
|
It's in PHP, isn't it?
Welcome to my world. PHP isn't a bad language in and of itself. Unfortunately, most PHP programmers are barely average. I've inherited several PHP projects now and most of it is pretty shitty. I've even spurned PEAR modules for their inherintly poor design and coding.
Wade.
Q:Is it proper to eat cheeseburgers with your fingers? A:No, the fingers should be eaten separately.
|
Post #318,502
12/13/09 9:52:49 AM
|
You've got a typo there
Unfortunately, most PHP programmers are barely average. I've inherited several PHP projects now and most of it is pretty shitty.
Languages that are harder to work with may filter out some of the lesser programmers, but that just means the ones that are left cause more subtle and obscure bugs. The language doesn't exist that keeps the determined idiot from writing shit with it.
--
Drew
|
Post #318,521
12/13/09 5:21:32 PM
|
I was speaking only from my own experience. :-/
Which is inheriting PHP code. But point taken. I'm embarking on some serious Java programming here and it's just occurred to me that I might find some shit in there, too, despite the presence of such involved things like Hibernate and Struts which need to be complex enough that most programmers are bad at writing.
FWIW, I've noticed that obscure languages (e.g. Icon) tend to have better programmers because there's a certain enthusiasm required to use it.
Wade.
Q:Is it proper to eat cheeseburgers with your fingers? A:No, the fingers should be eaten separately.
|