Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Hooks api
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brandon Keepers  
View profile  
 More options Oct 10 2011, 11:37 pm
From: Brandon Keepers <bran...@opensoul.org>
Date: Mon, 10 Oct 2011 23:37:00 -0400
Subject: Hooks api

 Hello Qu Comrades (all 3 of you),  

I've started working on an implementation of hooks and thought I would get some feedback before going any further.

https://github.com/bkeepers/qu/compare/master…hooks (https://github.com/bkeepers/qu/compare/master...hooks)

To summarize the major changes: Jobs must now extend Qu::Job. This is something I debated about a lot in the initial implementation of Qu. I initially implemented it as a subclass of Qu::Job, but then decided follow Resque and make jobs simply a class with a perform class method for simplicity's sake. I have since changed my mind and think there's a lot of power in using richer objects for jobs.

The Qu:Job class currently implements 4 hooks (perform, complete, release, failure). Others will be coming soon, but I still need to figure out some implementation details.  A hook is a method that is called before, after, or around one of the events.  Calling `halt` in a before hook will prevent the original action from occurring (example: `halt` in a before_failure hook will prevent the job from being marked as failed) and will stop all other hooks.

Here are some examples of what a job using hooks will look like:

class MyJob < Qu::Job
  attr_reader :thing

  around_perform :timeout  
  before_perform :notify_before_perform
  after_perform :notify_before_perform

  before_failure :ignore_annoying_errors

  def initialize(thing_id)
    @thing = Thing.find(thing_id)
  end

  def perform
    # …
  end

private

  def notify_before_perform
    notifier.announce "Performing job #{id}"
  end

  def notify_after_perform
    notifier.announce "Done performing job #{id}"
  end

  def ignore_annoying_errors(e)
    halt if e < ErrorIDoNotCareAbout
  end

  def timeout
    Timeout.timeout(60) do
      yield
    end
  end
end

So, what do you think so far? Anything you would do differently?

Thanks,
Brandon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Hoyt  
View profile  
 More options Oct 11 2011, 10:10 am
From: Jonathan Hoyt <h...@orderedlist.com>
Date: Tue, 11 Oct 2011 10:10:18 -0400
Local: Tues, Oct 11 2011 10:10 am
Subject: Re: [Qu] Hooks api

 Looks good to me. How do you handle completely changing the API on a library and letting folks know that you did so? Just update the readme, or do you try and reach out to those you know are using it?  


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brandon Keepers  
View profile  
 More options Oct 11 2011, 10:27 am
From: Brandon Keepers <bran...@opensoul.org>
Date: Tue, 11 Oct 2011 10:27:09 -0400
Local: Tues, Oct 11 2011 10:27 am
Subject: Re: [Qu] Hooks api

Once Qu reaches 1.0, I'll follow semantic versioning (http://semver.org/). Until then, I'll document it and make it clear that any change in minor version (0.1 => 0.2) will be backwards incompatible.

Since qu is so new and has so few users, I'm not too worried about it.

=b


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craig wickesser  
View profile  
 More options Oct 12 2011, 5:24 am
From: craig wickesser <codecr...@gmail.com>
Date: Wed, 12 Oct 2011 02:24:28 -0700 (PDT)
Local: Wed, Oct 12 2011 5:24 am
Subject: Re: [Qu] Hooks api

I'm cool with having to subclass Qu::Job. I generally don't like having to
subclass something but in the case of a "job" class, they already tend to be
lean and focused (in my experience so far).

One thing I'd like is clear documentation (maybe even a flow diagram, or
something similar) about the hooks, when are they invoked? what happens if
an exception is raised inside of a hook? what happens when you call "halt"
(i.e. in a before_perform hook?).

-craig


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »