Hi all,

first of all thanks for this great module, it really makes things easier.

I've created several job types on my site. Recruiters can select categories when posting a job, jobseekers can select categories they're interested in at the registration section. My question is, would it be possible to setup a jobs by email function? That means when a job post matches the category a jobseeker selected an automated email get sent to them. For example I'm interested in "Driving jobs" so I select it when registering and a recruiter posts a job into that category -> I receive an email notification.

Any help appreciated!

Thanks

Comments

richygecko’s picture

I was trying to do the same thing by using notifications module and subscriptions module and it didn't go all that well I forget the exact problems but it didn't exactly do what i was looking for. What I did in the end was enable the RSS link in the view for the JOB searches. That way a job seeker could save their search and receive the RSS items in their RSS reader.

xamount’s picture

I have done this successfuly by creating a custom module for my site that uses hook_nodeapi and hooks into the op = insert

Basically this is what the module does: when a job is created (op = insert), a function is called that scans all the resume nodes and finds jobseekers that match the "category" of the job. In my case, this "category" was field of work which was a normal cck field.

All the matching jobseekers and then notified by sending them an email which contains a link to the job and other userful links in the email.

NB for large sites (like mine) where there are possibly thousands of matching jobseekers than can be found, this would mean that when a job is created 1000 emails will have to be sent when a recruiter clicks on "submit" when creating a job node. As a result, from the time you click submit until you see the confirmation page that tells you the job has been created can be a couple of seconds or minutes. This is because drupal is trying to send >1000 emails to all the matching jobseekers.

It gets worse when you have multiple jobs being created at the same time. basically, your server will choke at some point.

So what I ended up doing was queueing the jobseekers in a database table and using hook_cron to send x amount of emails per cron. This way the sending of emails are throttled and eases up on the cpu resources. Jobseekers would not be notified IMMEDIATELY, but they will eventually, and this would depend on how many times you run cron and how big your "x amount" value is.

I would have posted the code here, but it will not make much sense as the code is customized to my site and my use of cck field names etc.

kbahey’s picture

This is a very good solution.

You can post sample pseudo-code instead. It will help a lot of people. Better yet, include it in the README.txt under a section called: Advanced Usage or something.

Regarding this issue:

NB for large sites (like mine) where there are possibly thousands of matching jobseekers than can be found, this would mean that when a job is created 1000 emails will have to be sent when a recruiter clicks on "submit" when creating a job node. As a result, from the time you click submit until you see the confirmation page that tells you the job has been created can be a couple of seconds or minutes. This is because drupal is trying to send >1000 emails to all the matching jobseekers.

It gets worse when you have multiple jobs being created at the same time. basically, your server will choke at some point.

There is a solution to this, I wrote the http://drupal.org/project/queue_mail module which interfaces with the job_queue module. What it does is that it makes all emails go thru cron, so the user will not see a delay when they click submit.

This works for any module that sends mails and solves the issue you describe without having to resort to custom code for each module.

xamount’s picture

damn...your queue_mail module came out a few months late!

Well here is the pseudo code. I tried to make it generic so any user can re-use it for more advanced email throttling. This is for advanced users only so only do this if you know what you are doing.

In your custom module (not the job search module):

<?php
function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global $user;

  switch ($op) {

  case 'insert':
    	
  if ($node->type == 'jobs') {
    $employer_node = node_load(...);  //load the node id of the employer who posted the job
    	
    $query = 'INSERT INTO {yourmodule_email_batch} (job_nid, resume_nid, uid, timestamp)....//basically you find all the matching  jobseekers and insert their uid and resume_id in the table. This table would have to be created in yourmodule.install file
          
}   		
?>

Next you set up hook_cron to do the throttling:

<?php
function hook_cron() {
  // SELECT a bunch of the most recent batched emails and start sending.
  $results = db_query_range("SELECT * FROM {yourmodule_email_batch} ORDER BY timestamp ASC", 0, EMAIL_BATCH_LIMIT);

//EMAIL_BATCH_LIMIT is the xamount value I mentioned earlier that defines how many emails you want to sent out per cron. This is a global variable that you should define at the top of your module. The higher the value, means more emails are sent out per cron, but more cpu and memory resources are used. Pay attention to your PHP memory_limit value here.

  while ($result = db_fetch_array($results)) {
    // load in each unique job. 
      $jobs[] = node_load($result['job_nid']);
    }

    // and a list of all the resumes.
    $resumes[$result['job_nid']][] = node_load($result['resume_nid']); 
  }

  if (db_num_rows($results) > 0) {
  	_batch_email($jobs, $resumes); 
  }
}
?>

The function _batch_email is a helper function that sends out batch emails. You have the $jobs and $resumes as arguments, so you can format the email to your liking. Remember to delete the jobseeker from the table after you sent them an email.

I know this code looks a bit messy, but it was hard trying to make it generic as the original code was tightly integrated with my site and other functions etc. But hopefully, it will give you an idea of how to do the throttling.

@kbahey: can you take a look at this code and make it more pseudo-ish/generic so I can include it somehow in README.txt under advanced usage?

kbahey’s picture

I meant the pseudo code for the searching/matching, since the queue_mail module solves the other problem.