aasm column: :status do
state :pending, initial: true
state :running, :completed, :failed
event :start, success: :success_event_start, after: :after_event_start, after_commit: :after_commit_event_start do
transitions from: :pending, to: :running,
after: :after_transition_from_pending_to_running,
success: :success_transition_from_pending_to_running
end
event :complete do
transitions from: :running, to: :completed
end
event :fail do
transitions from: :running, to: :failed
end
end
Se ejecuta el método after_transition_from_pending_to_running
.
status_was
:pending
status_previously_was
:nil
Se ejecuta el método after_event_start
.
status_was
:pending
status_previously_was
:nil
Se ejecuta el método after_transition_from_pending_to_running
.
status_was
:pending
status_previously_was
:nil
Si fallan las validaciones, se termina aquí y no sigue ejecutando las siguientes callbacks.
Se ejecuta la sentencia SQL necesaria para actualizar el campo. En este punto siempre que estemos dentro de la misma transacción, veremos el campo actualizado si hacemos otra consulta.
Se ejecuta el método success_transition_from_pending_to_running
.
status_was
:running
status_previously_was
:pending
Se ejecuta el método success_event_start
.
status_was
:running
status_previously_was
:pending
Se ejecuta el método after_event_start
.
status_was
:running
status_previously_was
:pending
En este punto si se consulta a la base de datos desde fuera de la transacción, se tienen acceso a los cambios.
Se ejecuta el método after_commit_event_start
.
status_was
:running
status_previously_was
:pending