Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-619

Crash on _realm->commit_transaction()

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      SDK and version

      SDK : RealmSwift
      Version: (10.7.2)

      Observations

      • How frequent do the crash occur? - Few times a day
      • Does it happen in production or during dev/test? - Production
      • Can the crash be reproduced by you? - Not exect
      • Can you provide instructions for how we can reproduce it? - Unfortunately not

      Crash log / stacktrace

      /Users/realm/workspace/realm_realm-core_release_10.5.5/src/realm/object-store/impl/realm_coordinator.cpp:744: [realm-core-10.5.5] Assertion failed: m_notifier_sg->get_version() + 1 == new_version.version [395, 396]
      0   Realm                               0x0000000109d56168 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
      1   Realm                               0x0000000109d5640c _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
      2   Realm                               0x0000000109be7c14 _ZN5realm11Transaction5closeEv + 0
      3   Realm                               0x0000000109e1f714 _ZN5realm5_impl16RealmCoordinator12commit_writeERNS_5RealmE + 548
      4   Realm                               0x0000000109e99bb0 _ZN5realm5Realm18commit_transactionEv + 220
      5   Realm                               0x0000000109b29078 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 544
      6   RealmSwift                          0x000000010aaa0a44 $s10RealmSwift0A0V11commitWrite16withoutNotifyingySaySo20RLMNotificationTokenCG_tKF + 172
      7   RealmSwift                          0x000000010aaa0460 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 472
      8   Staging iPad App                    0x0000000104f46a5c $s16Staging_iPad_App19CompanyRealmServiceC5write16withoutNotifying_xSaySo20RLMNotificationTokenCGSg_xyKXEtKlF + 440
      9   Staging iPad App                    0x0000000104f47a84 $s16Staging_iPad_App19CompanyRealmServiceCAA0F0A2aDP5write16withoutNotifying_qd__SaySo20RLMNotificationTokenCGSg_qd__yKXEtKlFTW + 36
      10  Staging iPad App                    0x0000000105061eb0 $s16Staging_iPad_App8OrderApiC6create_8location0G5Table_yAA7AccountCSg_AA8LocationCSgAA0jH0CSgyAA0D0CSgctF + 436
      11  Staging iPad App                    0x00000001057f9444 $s16Staging_iPad_App14OrderViewModelC09addItemToD0_8quantity4note14useCustomPrice5price16attributeOptions12discountInfoyAA7ProductC_SdSSSbSdSayAA0t9AttributeS0VGAA08DiscountS0VtF + 1060
      12  Staging iPad App                    0x00000001054efecc $s16Staging_iPad_App11ProductCellV4bodyQrvgyycfU_ + 1152
      13  SwiftUI                             0x00000001978d2e30 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 4906544
      14  SwiftUI                             0x0000000197be9f28 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 8146728
      15  SwiftUI                             0x0000000197953b98 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434264
      16  SwiftUI                             0x0000000197953bc0 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434304
      17  SwiftUI                             0x0000000197953b98 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434264
      18  SwiftUI                             0x0000000197942764 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5363556
      19  SwiftUI                             0x0000000197994e6c 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5701228
      20  SwiftUI                             0x0000000197e21e50 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10473040
      21  SwiftUI                             0x0000000197e1ff28 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10465064
      22  SwiftUI                             0x0000000197e20be0 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10468320
      23  UIKitCore                           0x00000001933acd2c 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7413036
      24  UIKitCore                           0x00000001938f525c 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12952156
      25  UIKitCore                           0x00000001933a2bd4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7371732
      26  UIKitCore                           0x00000001933a28b4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7370932
      27  UIKitCore                           0x00000001938aae30 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12647984
      28  UIKitCore                           0x00000001938841d4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12489172
      29  UIKitCore                           0x000000019390e0ec 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13054188
      30  UIKitCore                           0x00000001939110a4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13066404
      31  UIKitCore                           0x0000000193908550 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13030736
      32  CoreFoundation                      0x0000000190e2a76c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661356
      33  CoreFoundation                      0x0000000190e2a668 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661096
      34  CoreFoundation                      0x0000000190e29960 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 657760
      35  CoreFoundation                      0x0000000190e23a8c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 633484
      36  CoreFoundation                      0x0000000190e2321c CFRunLoopRunSpecific + 600
      37  Foundation                          0x00000001920d2df0 7698BF3E-0CF6-31C0-85E9-562714F01276 + 36336
      38  Foundation                          0x00000001920d2cbc 7698BF3E-0CF6-31C0-85E9-562714F01276 + 36028
      39  CSJPOSLibSwift                      0x000000010b263308 +[CSJPOSPrinter searchCitizenPrinter:withSearchTime:result:] + 452
      40  Staging iPad App                    0x000000010552bdc8 $s16Staging_iPad_App17BasePrinterRenderC02isE18ConnectedToNetWorkySbSSFZ + 320
      41  Staging iPad App                    0x000000010553a258 $s16Staging_iPad_App12PrintManagerC20setConnectedPrinters33_CDA07C824DA047C39954A55FFBC3FC95LLyyF + 516
      42  Staging iPad App                    0x0000000105530408 $s16Staging_iPad_App12PrintManagerC16connectToPrinteryyAA0D3JobCF + 468
      43  Staging iPad App                    0x0000000105530220 $s16Staging_iPad_App12PrintManagerC10prepareJobyyAA0dG0CF + 236
      44  Staging iPad App                    0x00000001055300ac $s16Staging_iPad_App12PrintManagerC5startyyFySayAA0D3JobCGcfU_ + 508
      45  Staging iPad App                    0x0000000105215f54 $s16Staging_iPad_App12ListObserverCyACyxG10RealmSwift7ResultsVyxGcfcyAE0F16CollectionChangeOyAHGcfU_ + 1248
      46  RealmSwift                          0x000000010aabeeb0 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegg_AGIegn_AA0aC5ValueRzlTR + 60
      47  RealmSwift                          0x000000010aaaed18 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_ + 1688
      48  RealmSwift                          0x000000010aaaf438 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_TA + 112
      49  RealmSwift                          0x000000010aa66dd0 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegngg_AdgIIegggg_TR + 88
      50  RealmSwift                          0x000000010aa66ecc $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegggg_AdGSo7NSErrorCSgIeyByyy_TR + 156
      51  Realm                               0x00000001099a89bc _ZN12_GLOBAL__N_125CollectionCallbackWrapperclERKN5realm19CollectionChangeSetESt13exception_ptr + 532
      52  Realm                               0x00000001099a85cc _ZN5realm24CollectionChangeCallback4ImplIN12_GLOBAL__N_125CollectionCallbackWrapperEE5afterERKNS_19CollectionChangeSetE + 76
      53  Realm                               0x0000000109e156c8 _ZN5realm5_impl18CollectionNotifier13after_advanceEv + 520
      54  Realm                               0x0000000109e22654 _ZN5realm5_impl16RealmCoordinator23process_available_asyncERNS_5RealmE + 1120
      55  Realm                               0x0000000109e9a4bc _ZN5realm5Realm6notifyEv + 360
      56  Realm                               0x0000000109e35248 _ZNSt3__110__function6__funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 48
      57  CoreFoundation                      0x0000000190e2a76c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661356
      58  CoreFoundation                      0x0000000190e2a668 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661096
      59  CoreFoundation                      0x0000000190e29960 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 657760
      60  CoreFoundation                      0x0000000190e23a8c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 633484
      61  CoreFoundation                      0x0000000190e2321c CFRunLoopRunSpecific + 600
      62  GraphicsServices                    0x00000001a89ef784 GSEventRunModal + 164
      63  UIKitCore                           0x0000000193863ee8 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12357352
      64  UIKitCore                           0x000000019386975c UIApplicationMain + 168
      65  Staging iPad App                    0x0000000105102eec main + 88
      66  libdyld.dylib                       0x0000000190ae36b0 21B19919-1334-38BC-B233-896E929945E0 + 5808!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2021-03-11 17:34:37.613819+0100 Staging iPad App[1032:266875] /Users/realm/workspace/realm_realm-core_release_10.5.5/src/realm/object-store/impl/realm_coordinator.cpp:744: [realm-core-10.5.5] Assertion failed: m_notifier_sg->get_version() + 1 == new_version.version [395, 396]
      0   Realm                               0x0000000109d56168 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
      1   Realm                               0x0000000109d5640c _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
      2   Realm                               0x0000000109be7c14 _ZN5realm11Transaction5closeEv + 0
      3   Realm                               0x0000000109e1f714 _ZN5realm5_impl16RealmCoordinator12commit_writeERNS_5RealmE + 548
      4   Realm                               0x0000000109e99bb0 _ZN5realm5Realm18commit_transactionEv + 220
      5   Realm                               0x0000000109b29078 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 544
      6   RealmSwift                          0x000000010aaa0a44 $s10RealmSwift0A0V11commitWrite16withoutNotifyingySaySo20RLMNotificationTokenCG_tKF + 172
      7   RealmSwift                          0x000000010aaa0460 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 472
      8   Staging iPad App                    0x0000000104f46a5c $s16Staging_iPad_App19CompanyRealmServiceC5write16withoutNotifying_xSaySo20RLMNotificationTokenCGSg_xyKXEtKlF + 440
      9   Staging iPad App                    0x0000000104f47a84 $s16Staging_iPad_App19CompanyRealmServiceCAA0F0A2aDP5write16withoutNotifying_qd__SaySo20RLMNotificationTokenCGSg_qd__yKXEtKlFTW + 36
      10  Staging iPad App                    0x0000000105061eb0 $s16Staging_iPad_App8OrderApiC6create_8location0G5Table_yAA7AccountCSg_AA8LocationCSgAA0jH0CSgyAA0D0CSgctF + 436
      11  Staging iPad App                    0x00000001057f9444 $s16Staging_iPad_App14OrderViewModelC09addItemToD0_8quantity4note14useCustomPrice5price16attributeOptions12discountInfoyAA7ProductC_SdSSSbSdSayAA0t9AttributeS0VGAA08DiscountS0VtF + 1060
      12  Staging iPad App                    0x00000001054efecc $s16Staging_iPad_App11ProductCellV4bodyQrvgyycfU_ + 1152
      13  SwiftUI                             0x00000001978d2e30 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 4906544
      14  SwiftUI                             0x0000000197be9f28 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 8146728
      15  SwiftUI                             0x0000000197953b98 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434264
      16  SwiftUI                             0x0000000197953bc0 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434304
      17  SwiftUI                             0x0000000197953b98 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5434264
      18  SwiftUI                             0x0000000197942764 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5363556
      19  SwiftUI                             0x0000000197994e6c 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 5701228
      20  SwiftUI                             0x0000000197e21e50 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10473040
      21  SwiftUI                             0x0000000197e1ff28 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10465064
      22  SwiftUI                             0x0000000197e20be0 042A2FB0-B73F-38C4-B4E9-1AC4262918E5 + 10468320
      23  UIKitCore                           0x00000001933acd2c 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7413036
      24  UIKitCore                           0x00000001938f525c 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12952156
      25  UIKitCore                           0x00000001933a2bd4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7371732
      26  UIKitCore                           0x00000001933a28b4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 7370932
      27  UIKitCore                           0x00000001938aae30 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12647984
      28  UIKitCore                           0x00000001938841d4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12489172
      29  UIKitCore                           0x000000019390e0ec 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13054188
      30  UIKitCore                           0x00000001939110a4 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13066404
      31  UIKitCore                           0x0000000193908550 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 13030736
      32  CoreFoundation                      0x0000000190e2a76c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661356
      33  CoreFoundation                      0x0000000190e2a668 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661096
      34  CoreFoundation                      0x0000000190e29960 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 657760
      35  CoreFoundation                      0x0000000190e23a8c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 633484
      36  CoreFoundation                      0x0000000190e2321c CFRunLoopRunSpecific + 600
      37  Foundation                          0x00000001920d2df0 7698BF3E-0CF6-31C0-85E9-562714F01276 + 36336
      38  Foundation                          0x00000001920d2cbc 7698BF3E-0CF6-31C0-85E9-562714F01276 + 36028
      39  CSJPOSLibSwift                      0x000000010b263308 +[CSJPOSPrinter searchCitizenPrinter:withSearchTime:result:] + 452
      40  Staging iPad App                    0x000000010552bdc8 $s16Staging_iPad_App17BasePrinterRenderC02isE18ConnectedToNetWorkySbSSFZ + 320
      41  Staging iPad App                    0x000000010553a258 $s16Staging_iPad_App12PrintManagerC20setConnectedPrinters33_CDA07C824DA047C39954A55FFBC3FC95LLyyF + 516
      42  Staging iPad App                    0x0000000105530408 $s16Staging_iPad_App12PrintManagerC16connectToPrinteryyAA0D3JobCF + 468
      43  Staging iPad App                    0x0000000105530220 $s16Staging_iPad_App12PrintManagerC10prepareJobyyAA0dG0CF + 236
      44  Staging iPad App                    0x00000001055300ac $s16Staging_iPad_App12PrintManagerC5startyyFySayAA0D3JobCGcfU_ + 508
      45  Staging iPad App                    0x0000000105215f54 $s16Staging_iPad_App12ListObserverCyACyxG10RealmSwift7ResultsVyxGcfcyAE0F16CollectionChangeOyAHGcfU_ + 1248
      46  RealmSwift                          0x000000010aabeeb0 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegg_AGIegn_AA0aC5ValueRzlTR + 60
      47  RealmSwift                          0x000000010aaaed18 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_ + 1688
      48  RealmSwift                          0x000000010aaaf438 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_TA + 112
      49  RealmSwift                          0x000000010aa66dd0 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegngg_AdgIIegggg_TR + 88
      50  RealmSwift                          0x000000010aa66ecc $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegggg_AdGSo7NSErrorCSgIeyByyy_TR + 156
      51  Realm                               0x00000001099a89bc _ZN12_GLOBAL__N_125CollectionCallbackWrapperclERKN5realm19CollectionChangeSetESt13exception_ptr + 532
      52  Realm                               0x00000001099a85cc _ZN5realm24CollectionChangeCallback4ImplIN12_GLOBAL__N_125CollectionCallbackWrapperEE5afterERKNS_19CollectionChangeSetE + 76
      53  Realm                               0x0000000109e156c8 _ZN5realm5_impl18CollectionNotifier13after_advanceEv + 520
      54  Realm                               0x0000000109e22654 _ZN5realm5_impl16RealmCoordinator23process_available_asyncERNS_5RealmE + 1120
      55  Realm                               0x0000000109e9a4bc _ZN5realm5Realm6notifyEv + 360
      56  Realm                               0x0000000109e35248 _ZNSt3__110__function6__funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 48
      57  CoreFoundation                      0x0000000190e2a76c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661356
      58  CoreFoundation                      0x0000000190e2a668 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 661096
      59  CoreFoundation                      0x0000000190e29960 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 657760
      60  CoreFoundation                      0x0000000190e23a8c 727F2644-EB4E-3D57-BC2E-E6803BA92366 + 633484
      61  CoreFoundation                      0x0000000190e2321c CFRunLoopRunSpecific + 600
      62  GraphicsServices                    0x00000001a89ef784 GSEventRunModal + 164
      63  UIKitCore                           0x0000000193863ee8 8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12357352
      64  UIKitCore                           0x000000019386975c UIApplicationMain + 168
      65  Staging iPad App                    0x0000000105102eec main + 88
      66  libdyld.dylib                       0x0000000190ae36b0 21B19919-1334-38BC-B233-896E929945E0 + 5808!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
      

      Steps & Code to Reproduce

      Unfortunately I can't always reproduce it. But we have one printJob collection in the realm we are update print tasks.

      • We use an API we created for that (see attached code).
      • When you do use the app, once in a while its crashed like this.
      import Combine
      import Foundation
      import RealmSwift
      
      class AppState<T:Object>: ObservableObject {
          
          fileprivate var companyDb: Realm! = nil
          fileprivate var cancellables = Set<AnyCancellable>()
          
          init() {
              self.companyDb = ServiceProvider.shared.company.getDb()
              let realmPublisher = PassthroughSubject<ServiceProvider, Error>()
              
              realmPublisher.sink(receiveCompletion: { result in
                  // Check for failure.
                  if case let .failure(error) = result {
                      CrashlyticsManager.instance.logCrashlytics("Failed to log in and open realm: \(error.localizedDescription)")
                  }
               }, receiveValue: { provider in
                  // The realm has successfully opened.
                  // If no get database from service provider
                  if self.companyDb == nil {
                      self.companyDb = provider.company.getDb()
                  }
               })
              .store(in: &cancellables)
          }
          
          func update(_ objectId: String, updateData: [String: Any]) {
              if let object = self.getObjectById(objectId) {
                  let properties = object.objectSchema.properties
                  
                  for (key, value) in updateData {
                      let valueToUpdate = properties.filter({ $0.name == key })
                      
                      if valueToUpdate.count != 0 {
                          self.performOperation(object, objects: [], dbOperation: .update, objValue: value, objKey: key)
                      }
                  }
              } else {
                  logger.info("Object error : In getting corressponding object")
                  CrashlyticsManager.instance.logCrashlytics("Object error : In getting corressponding object")
              }
          }
          
          func getObjectById(_ objectIdStr: String) -> Object? {
              let objectId = String.getObjectId(objectIdStr)
              if let db = self.companyDb, let getObj = db.object(ofType: T.self, forPrimaryKey: objectId), getObj.isInvalidated == false {
                  return getObj
              } else {
                  return nil
              }
          }
          
          func createAll(_ objects: [Object]) {
              self.performOperation(Object(), objects: objects, dbOperation: .createAll, objValue: "", objKey: "")
          }
          
          func create(_ object: Object) {
              self.performOperation(object, objects: [], dbOperation: .create, objValue: "", objKey: "")
          }
          
          func delete(_ objectId: String) {
              if let object = self.getObjectById(objectId) {
                  self.performOperation(object, objects: [], dbOperation: .delete, objValue: "", objKey: "")
              } else {
                  logger.info("Object error : In getting corressponding object")
                  CrashlyticsManager.instance.logCrashlytics("Object error : In getting corressponding object")
              }
          }
          
          func deleteAll(_ objects: [Object]) {
              self.performOperation(Object(), objects: objects, dbOperation: .deleteAll, objValue: "", objKey: "")
          }
          
          // Private function: Common write for all db operations
          fileprivate func performOperation(_ object: Object, objects: [Object], dbOperation: Action, objValue: Any, objKey: String) {
              if let db = self.companyDb {
                  do {
                      try db.write({
                          if dbOperation == .update {
                              object.setValue(objValue, forKey: objKey)
                              db.add(object, update: .modified)
                          } else if dbOperation == .createAll {
                              db.add(objects, update: .all)
                          } else if dbOperation == .create {
                              db.add(object, update: .all)
                          } else if dbOperation == .delete {
                              db.delete(object)
                          } else if dbOperation == .deleteAll {
                              db.delete(objects)
                          }
                          
                          db.refresh()
                      })
                  } catch {
                      let objErr = "\(dbOperation) error : \(error.localizedDescription)"
                      logger.info("\(objErr)")
                      CrashlyticsManager.instance.logCrashlytics("\(objErr)")
                  }
              } else {
                  let err = "Company error : In getting company"
                  logger.info("\(err)")
                  CrashlyticsManager.instance.logCrashlytics("\(err)")
              }
          }
      }
      

      And this is a part in the Printjob manager where we write the tasks.

      ```
      func processQueue(_ printJobQueue: String) {
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.2)

      { self.appState.update(printJobQueue, updateData: ["isStarted": true, "deviceId": ServiceProvider.shared.session.getCurrentDeviceId()]) }
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                 // Process the queue jobs one by one
                if let jobFromQueue = self.queue.getRecentJob() {
                   self.getJobAfterBeingSet(jobFromQueue.id)
                   CrashlyticsManager.instance.logCrashlytics("3b:Print:Get jobs after beeing set")
               }
          }
      }
      
      func getJobAfterBeingSet(_ jobId: String) {
          if !jobId.isEmpty, let job = self.appState.getObjectById(jobId) as? PrintJob {
              if (job.deviceId == ServiceProvider.shared.session.getCurrentDeviceId()) && job.isStarted {
                  self.printJob(job, isFromReprint: false)
                  CrashlyticsManager.instance.logCrashlytics("4a:Print:Check if job is not started")
              } else {
                  DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
                      let jobError = "getJobAfterBeingSet"
                      logger.info("\(jobError)")
                      self.queue.cleanJobFromQueue(jobId)
                      self.appState.update(jobId, updateData: ["isStarted": false, "error": jobError])
                  }
              }
          }
      }
      
       func printJob(_ printJob: PrintJob, isFromReprint: Bool) {
          let bPrinted = printJob.isPrinted.value ?? false
          let jobCreatedOn = printJob.modifiedOn ?? Date()
          let dateDifference = Date.getDifference(start: jobCreatedOn, end:  Date())
          if bPrinted == false {
            if isFromReprint {
                 self.formPrinterReceipt(printJob)
                 CrashlyticsManager.instance.logCrashlytics("5:Print:Job executed - Reprint")
            } else {
                 if 0 ... 5 ~= dateDifference {
                     self.formPrinterReceipt(printJob)
                     CrashlyticsManager.instance.logCrashlytics("5:Print:Job executed")
                 }
              }
          }
      }
      
      func deleteJob(_ printJob: PrintJob) {
          self.appState.delete(printJob.id)
      }
      
      
      func createNewJob(_ printJob: PrintJob) {
          self.appState.create(printJob)
          
          DispatchQueue.main.asyncAfter(deadline: .now() + 10, execute: {
              self.setNotificationForCurrentReprintJob(printJob.printerId)
          })
      }
      

            Assignee:
            thomas.goyne@mongodb.com Thomas Goyne
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: