ruby - Upgrade to Rails 5 - Deadlock happening for Sidekiq Workers -
i upgraded rails version 4.2.5.2
5.0.0
. current sidekiq version 4.2.10
i have 2 models participation has many engagements.
for each engagement, have different instances of sidekiq worker running in parallel. , trying update same parent participation.
participation = @engagement.participation participation.update_attributes( likes_count: engagement_metrics_for_participation.likes, comments_count: engagement_metrics_for_participation.comments, shares_count: engagement_metrics_for_participation.shares, total_engagement: engagement_metrics_for_participation.total_engagement, total_impression: engagement_metrics_for_participation.total_impression )
now workers getting deadlock , running forever. tried http://api.rubyonrails.org/classes/activerecord/locking/pessimistic.html
and updated code
participation = @engagement.participation participation.with_lock participation.likes_count = engagement_metrics_for_participation.likes participation.comments_count = engagement_metrics_for_participation.comments participation.shares_count = engagement_metrics_for_participation.shares participation.total_engagement = engagement_metrics_for_participation.total_engagement participation.total_impression = engagement_metrics_for_participation.total_impression participation.save end
but still facing same issue. need solve issue.
first of should consider upgrading rails 5.0.2(latest when posting answer), since 5.0.0 not called stable , lot of bug fixes came after release.
secondly, since model code has not been shared can tell there in model thats causing updation fail, maybe validation errors, callback errors, etc.
a workaround suggest is, if don't care callbacks or validations particular method use update_columns
instead of update_attributes
skip model validations , wont trigger callbacks.
Comments
Post a Comment