Skip to content

Commit

Permalink
Extend rowlocking to non-FBOS clients also
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Jun 18, 2020
1 parent 24ef1d6 commit a5c4b02
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/controllers/api/abstract_controller.rb
Expand Up @@ -83,16 +83,23 @@ def resource # OVERRIDE THIS IN CHILD
nil
end

def stale_data?
if resource
updated_at = raw_json[:updated_at]
if updated_at
if resource.updated_at.as_json != updated_at
return true
end
end
end
return false
end

# If FarmBot OS goes offline for a very long time,
# you don't want to corrupt user data with stale records.
# The row lock is only enforced for FBOS devices (not the FE)
def maybe_enforce_row_lock
when_farmbot_os do
if raw_json[:updated_at] && resource
if resource.updated_at.as_json != raw_json[:updated_at]
render json: { stale_record: STALE_RECORD }, status: 409
end
end
if stale_data?
render json: { stale_record: STALE_RECORD }, status: 409
end
end

Expand Down

0 comments on commit a5c4b02

Please sign in to comment.