Example use case of callbacks

3 views
Skip to first unread message

Ben Mabey

unread,
Jul 14, 2010, 12:24:17 AM7/14/10
to karras-dev
Hi,
Just following up on the thread that was started on this commit:
http://github.com/wilkes/karras/commit/fe67b74e69380ca6961eeac675b8da70cb41eb9d

Wilkes:
"I removed [callbaks] so that I can get 0.4.0 release out. I'm not
convinced that the callback implementation is the way I want to do it,
so I pulled it out until I made my mind up.

I would love to see some examples of how you are using the callbacks.
I think the implementation that I removed was a bit of cargo cult
baggage and that there's a more idiomatic way to deal with it. I
haven't used them much so I'm speculating. The tentative plan is to go
with something more like Django's signals. Another idea is to use
technomancy's robert-hooke or a similar approach. I'll write something
after I play around with it and post it on karras-dev to get some
feedback."

I totally agree WRT cargo culting... The funny thing is that I
generally avoid AR-like callbacks on the Ruby side of things and
prefer to use observers. I must admit that karras' original
implementation of callbacks was a little awkward to work with.
Awkward in that it wasn't open to extension (if I can borrow an OO
term...). Composing several fns for the same CB is fine, but it
seemed wrong that I always had to modify the original entity file to
add such behavior. I haven't used Django's signals before but it
sounds like we are on the same page.

Aside from the dubious and admittedly abusive use of callbacks that I
alluded to in my other thread about references we do have legitimate
use cases for callbacks. The prime candidate being for reporting.
After a record is created we send it to a function that updates
several counts in other collections (so that reports are quick reads
as opposed to map-reduce operations). This is really the only real
use case I think we have and we typically only need it for after-
create (although I could see needing something similar for after-
update). In this case we don't "modify" the original entity at all
and so the thread-through aspect of the current CBs wasn't really
needed in this case.

Hope that helps and let me know if you have any other questions,
Ben


Wilkes Joiner

unread,
Jul 16, 2010, 4:19:21 PM7/16/10
to karras-dev
I put a bit of thought into this last night, and I think we can
support callback functionality without modifying karras by using
robert-hooke (http://github.com/technomancy/robert-hooke).

A simple example is here: http://gist.github.com/478437

The complex example is here: http://gist.github.com/478827
I'll write up a detailed description when I have time, but I think the
commented code should convey the idea.

Let me know what you think,
Wilkes

On Jul 13, 11:24 pm, Ben Mabey <b...@benmabey.com> wrote:
> Hi,
> Just following up on the thread that was started on this commit:http://github.com/wilkes/karras/commit/fe67b74e69380ca6961eeac675b8da...

Ben Mabey

unread,
Aug 3, 2010, 3:26:11 PM8/3/10
to karras-dev
Hi Wilkes,
Sorry I never responded to your emails about the new changes. I
haven't had time yet to try these suggestions out. I will email you
once I do and have formed an opinion on the approach.

Thanks,
Ben
Reply all
Reply to author
Forward
0 new messages