A Blog on Ruby on Rails, Social Networking, Digital Marketing, Politics, and Other Thoughts.

Tag Cloud

More on Workling

Posted: February 14th, 2010 | Author: monolith | Filed under: Uncategorized | Tags: , , | 1 Comment »

In a previous post I showed how to set up Starling and Workling for background processing. There, Starling and Workling were really used by a background process to send out scheduled email updates. Now, I want to use them for another type of event, like letting those who posted jobs on Commune2.com know immediately when someone applies for one of their jobs.  So this will be a non-scheduled event that triggers a real time email in the background.

If you have not set up Starling and Workling yet, please check out my previous post before moving on: http://www.terravetus.com/2010/01/starling-workling-god-and-whenever/

A prerequisites for moving forward (which you can learn from the previous post):

  • Starling is up and running
  • Workling is up and running

OK, now that you have made it this far…

Commune2.com allows people to post and apply for jobs. I would like to add a notification email when someone applies for a job. The email is triggered by an event, which in this case is a creation of a new job application. This could also be triggered by a controller, and maybe that’s the right thing to do. However, in this case, the triggering even is withing the model itself. So, in the job application model:

after_create :notify_job_poster_of_new_application

and

def notify_job_poster_of_new_application
  # do not send unless a job exists
  # do not send if the applicant is also the job posted
  # do not sent if the job is not open or not active
  if job and user != job.user and job.status.downcase == "open" # if true then it is open and also active
    MailingsWorker.async_new_job_application_notification(self)
  end
end

The MailingsWorker should have a new_job_application_notification method, and it looks like this:


  def new_job_application_notification(job_application)
    UserMailer.deliver_new_job_application_notification(job_application)
  end

Next, complete the UserMailer like any standard ActionMailer method; add some test scripts with Cucumber (actually, better start with it), and you are ready to go.

Remember: restart Workling!

Here is the full code and other changes:

http://github.com/monolith/commune2/commit/00dbe9411274da00996e327a76620b127e5d08d7


One Comment on “More on Workling”

  1. 1 johnny said at 1:54 AM on January 8th, 2011:

    cool

Leave a Reply