On Tue, Mar 29, 2011 at 05:20:45AM -0700, Simone Carletti wrote:
> 
> The method is supposed to take a workitem as argument and remove the 
> associated document from the storage.
> The line that confuses me is storage#method because I can't understand what 
> is it supposed to return.
> 
> If it returns true, it seems to mean "the record was not there", then Ruote 
> will raise an error.
> 
> If it returns something different that nil (for example?), then it seems the 
> action creates a recursion by calling itself again.
> Why? When does the recursion is supposed to end?

Hello Simone,

welcome to this mailing list.

The storage methods may seem weird. The general rule for the #put and #delete 
method is

  - return nil when success
  - return true when the record is gone (update/deletion failed)
  - return the current version of the record when the caller's version is
    out of date (and there is a current version).

put and delete both take a record, inside that record there is a _rev field. If 
the caller's _rev is different from the current version's rev, the operation 
failed and the current version is returned.

Now why "true" in case of gone ? Because it's easier to write code like

  do_it(record) && raise ArgumentError.new("record out of date or gone")

Those revision control mechanisms are needed when multiple workers are 
operating inside of a concurrence, or simply when two client requests are 
competing for a workitem.

The recursion [usually] stops at the second "volley" : the client code either 
receives a "true" (gone) or a new version of the record with which the 
operation will succeed.

If you're unlucky and have more than two client/threads/processes competing for 
a record you could go for more volleys.


Best regards,

-- 
John Mettraux - http://jmettraux.wordpress.com

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to