Assuming you want to write some data to a RFID card and some data to a database.
Theoretically the connection to the database might break at any time and the connection between the card and the card reader might break at any time too.
Insert a record before you start your update of the RFID card, then update this record when complete. In this way you'll also be able to spot half-completed updates, and act accordingly.
Insert a record into the database with a status of 'incomplete'. Give it a timestamp, a unique id, and any other pertinent information you require to uniquely describe the RFID write attempt
Write to RFID card
Update the record inserted in step 1. with a 'completed' or 'failure' status
Then have a process which resolves incomplete records after a timeout period has elapsed (either by trying again, or whatever else you want to do).
Do not try to hold open a database transaction while you communicate with your RFID card, as this will:
Give you unwanted (and potentially lengthy) locks on your database
Rollback upon failure, which will remove any evidence you tried to do something to your RFID card
Define 'somewhat'. True atomic way require the smartcard module to participate in a distributed transaction and I'm not aware of any smartcard API and/or provider supporting transaction.
Anything less atomic means not atomic and you can play games of retry and status until the cows come home, but unless the smartcard write is idempotent you have zero chance of correctness in the presence of failures. If the smartcard write is idempotent then is simply a matter of retry and ack logic: write to DB with status 'pending', commit, then write to smartcard, then write to DB with status 'Done'. On crash you need a process to scan for status 'Pending' and retry. Since the smartcard write is idempotent, the retry is safe. And yes, Using Tables as Queues is relevant here.
Theoretically the connection to the database might break at any time and the connection between the card and the card reader might break at any time too.
Insert a record before you start your update of the RFID card, then update this record when complete. In this way you'll also be able to spot half-completed updates, and act accordingly.
Insert a record into the database with a status of 'incomplete'. Give it a timestamp, a unique id, and any other pertinent information you require to uniquely describe the RFID write attempt
Write to RFID card
Update the record inserted in step 1. with a 'completed' or 'failure' status
Then have a process which resolves incomplete records after a timeout period has elapsed (either by trying again, or whatever else you want to do).
Do not try to hold open a database transaction while you communicate with your RFID card, as this will:
Give you unwanted (and potentially lengthy) locks on your database
Rollback upon failure, which will remove any evidence you tried to do something to your RFID card
Define 'somewhat'. True atomic way require the smartcard module to participate in a distributed transaction and I'm not aware of any smartcard API and/or provider supporting transaction.
Anything less atomic means not atomic and you can play games of retry and status until the cows come home, but unless the smartcard write is idempotent you have zero chance of correctness in the presence of failures. If the smartcard write is idempotent then is simply a matter of retry and ack logic: write to DB with status 'pending', commit, then write to smartcard, then write to DB with status 'Done'. On crash you need a process to scan for status 'Pending' and retry. Since the smartcard write is idempotent, the retry is safe. And yes, Using Tables as Queues is relevant here.