Alright, finally getting back into to grails coding after a long time away. For my test pet store application, I decided to take a day and create newsletter sender. Basically, it just takes an email address (submitted via a little form widget thingy), and stores it in a separate table the database. I'm not bothering with user accounts yet for the site, so I'm just keeping it in a stupidly simple table with just a database id and the address itself. There's also a controller function for removing an address from the list (handy I should think).
Now that I've got email addresses to send to, I need to actually send the newsletters. Before tackling that, though, I want to send out the newsletters on a periodic basis, so i need a scheduling/cron like component. I decided to use the Quartz plugin for Grails. We use it at my $DAYJOB, and it's been an excellent workhorse there. After installing the plugin (grails install-plugin quartz), and creating a job (app-home/grails-app/job/SendNewletterJob.groovy), I was 80% done. I just had to define my scheduling and implement the execute() method, which calls my message send service. Easy! Here's my source:
class SendNewsletterJob {
def timeout = 9000l //runs every nine seconds (only for testing!)
def emailService
def execute() {
emailService.sendNewsletter()
}
}
Now for actually pushing the newsletter to the users. I created an app-home/grails-app/services/EmailService.groovy. In Grails parlance, from what I understand, a "service" is not a web-service (REST or SOAP), per se, but more like the Eric Evans DomainDrivenDesign notion of a service. Currently (May 2008) there is no nice plugin for sending email, but there is a nice document on the Grails site that describes how to create a mechinism that wraps Spring mail. I just ripped off the example EmailService, dropped my smtp host values into my grails-app/conf/spring/resources.xml, and I'm business.
Altogether, this project took less than four hours, most of which was fishing around playing with config settings and such. I'm trying to think what the parallel time investment would have been for a straight-up Java implementation. Hmmmmm.........
Showing posts with label grails. Show all posts
Showing posts with label grails. Show all posts
Friday, May 23, 2008
Thursday, April 3, 2008
Starting with Grails
In an effort to branch out an learn my "one language per year" like a good little developer, I've decided to start tooling around with Groovy and it's most famous offspring, Grails. I spent a week on a test app just to get my feet wet with the Grails conventions for GSPs/Controllers/Domain object and such, and I must admit that it's been soooooo easy to get things up and running. And not having to recompile and bounce the web-app every time I make a change is nice - even though when I change a domain class the web-app bounces itself (controllers are better in this regard).
For a nice-sized project with Grails, I'm going to implement a basic e-commerce site as I have a little bit of experience in that domain :). I'm planning on attacking it in a TDD manner, and applying lots of YAGNI (wow, I really need to master that skill!). I'm also going to integrate with Google Checkout for doing purchases - all test/beta/sandbox, nothing for real. I've done integrations with credit card processors, loyalty point programs, and PayPal, so I figured I'd checkout Google's API and see what I find.
I'm also curious to see how grails can deal with HTTP header things like ETags and If-Modified and such. I'm not totally sure if that's the domain of the web-app or web server, but I'm itching to find out - as I'm on a limited bandwidth host, and I need to conserve by bandwidth bytes!
More reports as I progress.
For a nice-sized project with Grails, I'm going to implement a basic e-commerce site as I have a little bit of experience in that domain :). I'm planning on attacking it in a TDD manner, and applying lots of YAGNI (wow, I really need to master that skill!). I'm also going to integrate with Google Checkout for doing purchases - all test/beta/sandbox, nothing for real. I've done integrations with credit card processors, loyalty point programs, and PayPal, so I figured I'd checkout Google's API and see what I find.
I'm also curious to see how grails can deal with HTTP header things like ETags and If-Modified and such. I'm not totally sure if that's the domain of the web-app or web server, but I'm itching to find out - as I'm on a limited bandwidth host, and I need to conserve by bandwidth bytes!
More reports as I progress.
Subscribe to:
Posts (Atom)