Date post: | 18-Jan-2017 |
Category: |
Engineering |
Upload: | manohar-shetty |
View: | 191 times |
Download: | 0 times |
HOW I MISSED MY DATE- A STORY AROUND SOFT DELETABLE PATTERN
By Manohar Shetty
A STORY ABOUT A STORY THAT..Took me 4 days to finish.3 PRs were rejected before it goes to master.Made me to miss a Holi celebration, a friends meet and alsoa DATE (though there was no time limit attached to it).
CONTEXTThe task was to Implement a "Account Reset” feature(from
multi-user account to single user account) //Account class Account < ActiveRecord::Base has_many :usersend
//User class User < ActiveRecord::Base has_many :images has_many :videos has_many :audio_files has_many :text_filesend
TIMEOUT
Solution - Simple! Move the deletion of resources out oftransaction with the help of delayed jobs..
ROLLBACK
Solution - Test whether the user is deleted or not beforedeleting the resources of user. If user exists in DB then don’t
delete the resources.
TOO EARLY
Solution - Send a delay param to [sidekiq](https://github.com/mperham/sidekiq) job. so that it is picked
up for execution after some time.
UNKNOWN TRANSACTION TIME
Solution Initialize the sidekiq job on `after_commit` callback.
SOFT DELETABLEDid Soft Deletable solve all my problems? Yessss!! :)
TIme Out - Resource are not deleted inside transactionRollback - Transaction can be easily rolled back as softdeletable just updates db record.
I had couple of options.
already in place solution using state machine.paranoia gem.
Awesome!!!!!. That does the Job.
LESSONS LEARNT:Technical:
“Business may require the functionality toappear immediate. However it does not mean
implementation of the same has to beimmediate as well. Simple patterns such as
“Soft Delete” give the perception ofimmediacy by abstracting away the details of
deletion.”
Philosophical:
“When something is broken don’t waste yourtime in fixing it, it will never be the same, try
to walk away, but make sure you don’t trip onit.”
Personal(too many):
“Don’t miss the date. Friday is not adoomsday, there is always a monday next to
it. You dont have to behave like you are superdedicated to finishing things right away,sometimes you just need to 'give it some
time'.”
www.mavenhive.in