mercredi 14 août 2019

Force database saves on failed state transitions using Aasm State Machine gem

I am using the Aasm gem to control state changes in my App. When there is a failed transition all Database changes made inside the event are rolled back.

I have certain places in my app where I have integrated with an external API. I have the following code

event :pause do
  before do
    integration.pause(self)
  end
  transitions from: :live, to: :paused
end

This makes an Api request to the service we have integrated with. When this is successful to saves a request log. However when it fails (say a 422), then my request log that is saved to the DB is rolled back.

How do I force these types of logs to be saved when there is a failed event? And if this is not possible what are the common ways people get around this sort of problem?

thanks

Aucun commentaire:

Enregistrer un commentaire