lml / lev

Ride the rails but don't touch them.
MIT License
2 stars 6 forks source link

WIP: Lev 7.0 #46

Closed joemsak closed 3 years ago

joemsak commented 8 years ago
class MyRoutine
  lev_routine outputs: { title: :_self,
                         description: { name: DescriptionRoutine, as: :desc }
                         _verbatim: [SubRoutine, :totally_exists, { name: OtherSub, as: :other }] }
end
class MyRoutine
  lev_routine outputs: { title: :_self }

  def exec
    set(title: 'Hello, world')
  end
end

result = MyRoutine.call
result.title #=> 'Hello, world'
class OtherSub
  lev_routine outputs: { description: :_self }

  def exec
    set(description: 'Wow a description')
  end
end

class SubRoutine
  lev_routine outputs: { title: :_self, description: OtherSub }

  def exec
    set(title: 'Hello world')
    run(:other_sub)
  end
end

class MyRoutine
  lev_routine outputs: { _verbatim: { name: SubRoutine, as: :sub } }

  def exec
    run(:sub)
  end
end

result = MyRoutine.call

result.title #=> 'Hello world'
result.description #=> 'Wow a description'
jpslav commented 8 years ago

first note on things to add / put back better: errors, working with activerecord errors (converting to lev), handlers, lev_form_for.

jpslav commented 8 years ago

Also, finishing up ability to kill a background job would be good.

joemsak commented 8 years ago

@jpslav Errors work begun with spec/errors_spec.rb , lib/lev/errors.rb, lib/lev/errors/error.rb, and #transfer_errors_from #fatal_error and #nonfatal_error in lib/lev/routine.rb

Feel free to let me know how I can make it more robust. I'm pretty sure #errors should just be the collection of Error instances instead of the #to_s version, but I thought this was a good first step

Dantemss commented 8 years ago

Currently lev's fatal_error won't actually rollback the DB state if the lev routine is called from inside a non-lev transaction. We could potentially either use requires_new: true when creating the transaction (in which case Lev should rollback its own internal state but not the outer transaction) or, if we want to rollback the entire thing, have Lev raise its own class of rollback error and/or maybe monkeypatch ActiveRecord::Transaction to rollback properly when that error is caught.

Dantemss commented 8 years ago

This is because Lev raises ActiveRecord::Rollback, which is caught and silently ignored by nested transactions: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions

Dantemss commented 3 years ago

OBE