Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_transactions: false does not work on activerecord #264

Open
trobrock opened this issue Jun 25, 2013 · 2 comments
Open

use_transactions: false does not work on activerecord #264

trobrock opened this issue Jun 25, 2013 · 2 comments

Comments

@trobrock
Copy link

I have something like the following:

  state_machine initial: :new, use_transactions: false do
    event :queue do
      transition :new => :queued
    end

    event :launch do
      transition :queued => :launching
    end

    event :provision do
      transition :launching => :provisioning
    end

    event :finish do
      transition :provisioning => :finished
    end

    after_transition on: :launch, :do => :launch_server
    after_transition on: :provision, :do => :provision_server
  end

I have use_transactions false, because I want the state transitions to be persisted during the callback methods so I can give the client updates on the state of the object. But when I added the use_transactions: false at the top it seems they are still ran within a transaction. Am I misunderstanding what that option does?

@johnnaegle
Copy link

I also have this issue:

class User < ActiveRecord::Base

  state_machine :state, :initial => :idle, :use_transactions => false do
    before_transition :idle => :calculating do |obj|
      puts "In Before IDLE => CALCULATING"
    end

    after_transition :idle => :calculating do |obj|
      puts "In After IDLE => CALCULATING"
    end

    event :start do
      transition :idle => :calculating
    end

    event :finish do
      transition :calculating => :idle
    end    
  end

end

When I start this I did not expect this to be wrapped in a transaction:

user.fire_events!(:start)
   (0.2ms)  BEGIN
In Before IDLE => CALCULATING
   (0.6ms)  UPDATE "users" SET "state" = 'calculating' WHERE "users"."id" = 21
In After IDLE => CALCULATING
   (1.4ms)  COMMIT

I'd like to see this:

user.fire_events!(:start)
In Before IDLE => CALCULATING
   (0.2ms)  BEGIN
   (0.6ms)  UPDATE "users" SET "state" = 'calculating' WHERE "users"."id" = 21
   (1.4ms)  COMMIT
In After IDLE => CALCULATING

Am I also mis-understanding use_transactions?

@johnnaegle
Copy link

I believe this is resolved by: #255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants