On 23/11/13 14:17, Justin Smith wrote:
you may want to make that (defonce generate-keys (get-key-generator))
and even better, add a "start" argument to get-key-generator so you
can persist across restarts of the vm.
Of course in a real app the key should be serialized to a persistent,
consistent, and shared data store.
Thanks Justin, I incoporated your suggestion, but your very last comment
made me think that I add a namespace how you would do the same thing
with a real database like datomic. That would be an excellent
opportunity to fiddle around with datomic which I've postponed long
enough. Ok so my latest 'in_memory' iteration can be found here:
https://github.com/jimpil/bankio/blob/master/src/bankio/in_memory.clj
it now does the following:
- key generation is thread-safe and can be resumed (assuming we know the
last id created)
-negative balance is allowed but is considered an overdraft for which
there is a penalty amount depending on the customer-account (defaults to
5). However there is an overdraft limit which is not allowed to be
surpassed and which also depends on the account (defaults to -300).
-closing an account is only allowed if its balance is 0. In addition,
I've used ensure instead of deref in the transaction to protect further
modifications on the closing account.
-since this is all in-memory I've basically copy-pasted some rudimentary
logging facilities adopted from the book "Clojure Programming" that logs
every ref change in a file for further inspection. There is also an
error log for all fails (i.e. overdraft-limit exceeded). In other words,
the exceptions within the transactions are caught and handled.
I've not got 8 days left so presumably I could add a datomic.clj and
show how one would do that with proper persistence...
Jim
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.