![]() ![]() ![]() Not sure what more you want.ĭjango orm do caching, so just send the object in as parameters. You can hook up some logging service, exception tracking service, or some dashboard services to manage it. But for big tasks that don't clearly belong to one model then you can always get away with a services module.įor errors just use regular logging. That's the Django way, and Django is so opinionated that straying too far from that can be trouble some. So I would just put business logic in the manager and in the model. I would just put the process you need to trigger on data changes in celery or something like it and either trigger the task in the code that do a change or even use signals to trigger it.įor you order example I assume you have an order model or table. The question remains : do you know of any similar tool that can solve these problems ? what do you think about the pattern, is there any tips you can share or warning you think about ? This leads us to the second part of the lib: any change made to a model can trigger one or more business logic code, that can themselves change the model, and re-trigger another business logic, and so on.Ī lot of attention has been laid to the edge cases (cycle of business logic), and I can explain further our finding about them. this does not solve the concurrency issue with parallel process though, and db lock will still be needed.Īnother feature of this proxy is that it tracks all changes made to the in-memory records. This helps to fix the hit to the db, and ensures any rule has the data up to date regarding what will be written in the end. return a consistent singleton for any distinct record of the model, with up to date data related to the previous “write” during the processing.delay “write” to the end of the process.aggressively cache all data that was fetched during the same process.Database wrapperįirst, any change/query to the database is handled by a Wrapper that will: We created a library that's split into two complementary components: a database proxy and a business rule execution Engine. We encountered this problem and after searching for a good pattern, we ended with this observation: it's not the cause of the change, nor the impact of the change that matters, it's the data that was updated that often triggered a business logic. If the code is well made the logic should be separated, and the data will be effectively hitting the database multiple times for the same process. ![]() and chained business logic will maybe need the same data twice. ex: we set the quantity to zero, this cancels the order => should we emit two mails (quantity updated, order canceled) ? Another problemīusiness logic will often need to look into the database to do its stuff. But what if a business rule triggers a change itself, and the common feature is too specialized to handle this case ? We risk to chain business rules recursively and we will need a more specific common logic that starts again to be duplicated. One good solution is to extract common features (create/update/ship/cancel an order) into a single place, and call it elsewhere. ex: we need to validate the data during creation AND update. emit a mail)».īut what if we want to create an order in two places ? what if we edit the order ? our CRUD oriented prototype is becoming more and more complex over time and duplication of logic is a thing. when the user clicks to «order» button, we create the order, and fire «business rule 1(ex. Probably shared by many softwares with business logic: at first, we write our business logic as a reaction on a user action. I'm going to describe what it does, but my main question is: do you know of a similar, opensource library that provides the same advantage, and what are its cons.įirst off, I will define a «business logic» as anything that will transform a handfull of data into some valuable stuff for the software's user: validating coherence, computing stuff, sending notifications, storing history of changes, creating a pdf, etc. provide an exhaustive list of errors recorded during business logic executionĪt my job, we are building a library to execute business logic around a data model in a natively optimized way.make all business rules explicitly in a single place.heavily lower database hit/write with consistency between write/read on the same (long) process.Is there a lib in python/django that allows to : ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |