How to handle firebase transactions offline? Swift

I am writing an IOS App in Swift and I am using Firebase as a database. In this app multiple users can simultaneously read a list of jobs .
Depending on the boolean value of a job only one user should be allowed to write to that job (node) and change its’s boolean value.

  1. After a write is completed at Users/UID/cus/bookingNumber , I need to save the same data to a different node, Cleaners/UID/bookingNumber.

First scenario would be to write to the first path in the body of the transaction runTransactionBlock and write to the second path in the completion handler, but Firebase Transactions (as per documentation) are not persisted across app restarts so there us a high risk that the database will be left in an inconsistent state.

  1. Second scenario would be to attempt to write to both paths Users/UID/cus/bookingNumber and Cleaners/UID/bookingNumber in one single transaction (not using the completion handler) , but I haven’t found any tutorial/documentation on how to write to multiple paths using firebase transactions. I want to use Firebase transactions because I don’t want multiple users to claim the same job. Only one user should be allowed to claim a job at a time.

I asked a question on stackoverflow too.

My data model

  1. Claim - Cleaner
    cleaner tries to claim booking at Users/UID/cus/bookingNumber

    if FIRMutableData contains a key ‘claimed’ or key:value “claimed”:true 
    
      write at Users/UID/cus/bookingNumber with
        cleanerUID:UEWUW*932324jkjsdf
     	 timeStampBookingClaimed:435353
     		    claimed:true
    
    
    1.1 write to Cleaners/UID/bookingNumber
         original booking containing updated data
    

This topic was automatically closed after 166 days. New replies are no longer allowed.