+ All Categories
Home > Engineering > How i missed my date a story around soft deletable pattern

How i missed my date a story around soft deletable pattern

Date post: 18-Jan-2017
Category:
Upload: manohar-shetty
View: 191 times
Download: 0 times
Share this document with a friend
13
HOW I MISSED MY DATE - A STORY AROUND SOFT DELETABLE PATTERN By Manohar Shetty
Transcript
Page 1: How i missed my date a story around soft deletable pattern

HOW I MISSED MY DATE- A STORY AROUND SOFT DELETABLE PATTERN

By Manohar Shetty

Page 2: How i missed my date a story around soft deletable pattern

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).

Page 3: How i missed my date a story around soft deletable pattern

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

Page 4: How i missed my date a story around soft deletable pattern

TIMEOUT

Solution - Simple! Move the deletion of resources out oftransaction with the help of delayed jobs..

Page 5: How i missed my date a story around soft deletable pattern

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.

Page 6: How i missed my date a story around soft deletable pattern

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.

Page 7: How i missed my date a story around soft deletable pattern

UNKNOWN TRANSACTION TIME

Solution Initialize the sidekiq job on `after_commit` callback.

Page 8: How i missed my date a story around soft deletable pattern

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.

Page 9: How i missed my date a story around soft deletable pattern

I had couple of options.

already in place solution using state machine.paranoia gem.

Awesome!!!!!. That does the Job.

Page 10: How i missed my date a story around soft deletable pattern

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.”

Page 11: How i missed my date a story around soft deletable pattern

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.”

Page 12: How i missed my date a story around soft deletable pattern

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'.”

Page 13: How i missed my date a story around soft deletable pattern

www.mavenhive.in


Recommended