by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 20 10:58
    fastengineer commented #396
  • Jun 03 11:33
    ericproulx opened #403
  • May 20 17:37
    thom-oman closed #350
  • May 20 17:37
    thom-oman commented #350
  • May 20 17:35
    arthurnn commented #350
  • May 19 16:10

    thom-oman on v7.2.0

    (compare)

  • May 15 09:32

    lawrencejones on lazily_configure_gaplock_prevention

    (compare)

  • May 15 09:32

    lawrencejones on master

    Lazily enable mysql gaplock pro… (compare)

  • May 15 09:32
    lawrencejones closed #402
  • May 15 09:19
    thom-oman review_requested #402
  • May 15 09:18
    thom-oman opened #402
  • May 15 09:18

    thom-oman on lazily_configure_gaplock_prevention

    Lazily enable mysql gaplock pro… (compare)

  • May 15 09:13

    thom-oman on lazily_configure_gaplock_prevention

    wip (compare)

  • May 15 08:51

    thom-oman on lazily_configure_gaplock_prevention

    -wip (compare)

  • May 15 08:29

    thom-oman on lazily_configure_gaplock_prevention

    WIP: lazily enable mysql gaploc… (compare)

  • May 15 07:56
    lawrencejones commented #401
  • May 15 07:50
    simmerz commented #401
  • May 15 07:40
    lawrencejones commented #401
  • May 14 21:24
    simmerz opened #401
  • May 12 14:11
    jurre commented #399
timothyp
@timothyp
Thanks for 1.2. That issue with rails 3.2 is all good now. Unfortunately a few issues crept in with the most_recent column stuff (which is great in principle BTW — I’d been considering it myself). Some are pretty minor/edge, but there are showstoppers for MySQL.
I can raise github issues, but at least one of them prob. needs some discussion. Better done on the issue than here, presumably?
Isaac Seymour
@isaacseymour
Hey @timothyp - GitHub issue would be good. A PR with some failing specs would be even better ;)
timothyp
@timothyp
I was planning PRs etc :) However, one of the problems is with the rake task to backfill migrations. I don’t think there are tests at present. Do you have any feelings on testing the rake task as-is, or extracting the body into a plain class for unit testing?
(I was assuming the PR’s should include the solutions, so no failing specs, just new ones…)
timothyp
@timothyp
Specifically, UPDATE …. FROM is non-ANSI and unsupprted by MySQL. The way to do it there is a self join (also non-standard — argh!). The best I’ve managed is to break it into select/update queries :( Couldn’t quite bludgeon ActiveRecord into a working all-in-one update_all (I wanted to so AR handles the db differences as it should). It was very close, but the self-join meant that a disambiguating table name was needed in the SQL generated for MySQL, but that causes PostgreSQL to blow up. I might have more of a play later.
Isaac Seymour
@isaacseymour
Ah, okay. We only test against Postgres because we don't use MySQL at all. Would be nice if the rake task worked for MySQL but I wouldn't be against just creating a second one instead
so rake statesman:backfill_most_recent_pg[Model] and rake statesman:backfill_most_recent_mysql[Model]
timothyp
@timothyp
Unless I’m missing something, it looks like the backfill_most_recent rake task discussed above still needed resolution, so I’ve finally raised an issue #168 with associated PR #169.
timothyp
@timothyp
Is there any interest in having something like after_commit for after_transition, but for before_transition and before the transaction. One possible reason for having this is to enable something relatively time-consuming (e.g. external API call) to happen as part of the transition, but in such a way that it doesn’t result in a long db transaction when using the ActiveRecord storage adapter. Or is there already a nice way to do this (or a reason not to!) that I’m missing?
Isaac Seymour
@isaacseymour
@timothyp: I'm generally unconvinced that lifecycle hooks are a good idea, so would tend to be :-1: on adding more of them to Statesman. In general I'd prefer to recommend having an object which wraps the call to Statesman::Machine#transition_to! and handles the before/after stuff. Don't know how other people feel about this stuff though.
timothyp
@timothyp
Calling something just before transition_to! was my fallback option :) However, I suspected I’d end up kind of reproducing what statesman does for the current before_transition, after_transition and after_transition(after_commit: true) because whatever it was would have to do varying things depending on the current state.
timothyp
@timothyp
I’m not too worried though. Either way would work, but having it in statesman felt like it might end up being tidier, at the cost of another callback type and a before_start: true parameter (bad name…) for before_transition and of course invoking the callbacks before the transaction in create_transition for the AR adapter (and in create for the other adapters).
Isaac Seymour
@isaacseymour
I think I'd personally be :+1: on totally removing the before/after transition hooks. On the other hand we're probably not going to do that, so we shouldn't turn down new features which are obvious extensions of existing ones just because I don't like some of the existing behaviour ;) If you want to put in a PR to add a pre-transaction hook I'd be happy to review and merge unless @barisbalic, @jackfranklin etc disagree
José Tomás Albornoz
@eljojo
hello, is this chat being used anymore?
Baris Balic
@barisbalic
It's not hugely active, but we try to support people that come here with questions or problems :)
José Tomás Albornoz
@eljojo
ok cool!
I just discovered the gem and I think it's really nice
I am interested in using it, but I'm having a small problem: I don't want to persist the whole history in the database, but I still want my model's state to be persisted
I thought a nice idea would be to modify the fallback in the "current_state" method of a Machine
https://github.com/gocardless/statesman/blob/master/lib/statesman/machine.rb#L192
if the fallback, in case there's no action, was to self.initial_state instead of self.class.initial_state, then I could implement my own behavior of how to get the current state for the machine.
Do you think that would be useful? if so I can open a PR
José Tomás Albornoz
@eljojo
This would probably only make sense with the Memory adapter
Baris Balic
@barisbalic
Off the top of my head I'm not sure if that makes sense or not, but I will give the code a read over tonight and get back to you, just stepping out now!
José Tomás Albornoz
@eljojo
ok have a good night!
just to be clear my use case is persisting the current state of an object without persisting the complete history.
thanks a lot!
Damien Hogan
@damienh
Hi, I am currently experience the issue documented here gocardless/statesman#29 I was wondering if anyone knows a work around?
I am using version 1.3.1 Rails 3.2 and Ruby 2.1.3
Damien Hogan
@damienh

In initializers I have

Statesman.configure do
  storage_adapter(Statesman::Adapters::MongoidTransition)
end

and the generator command I used was rails g statesman:mongoid_transition club ClubState

I have then gone on to add include Statesman::Adapters::MongoidTransition and has_many :states, class_name: "ClubState", autosave: false to my club model.

the generated club_state.rb

Looks like

class ClubState
  include Mongoid::Document
  include Mongoid::Timestamps

  field :to_state, type: String
  field :sort_key, type: Integer
  field :statesman_metadata, type: Hash

  include Statesman::Adapters::MongoidTransition

  index({ sort_key: 1 })

  belongs_to :club, index: true
end
Isaac Seymour
@isaacseymour
Looks like it was fixed by removing include Statesman::Adapters::MongoidTransition - have you tried that?
Damien Hogan
@damienh
I removed it and and continued on with implementing but the moment I add states to my ClubState I get NoMethodError: undefined method 'state' for ClubState:Class
state :pending, initial: true
state :active
state :suspended
Are there any docs on how to best implement statesman with Mongoid?
Damien Hogan
@damienh
ignore me I sorted that :)
Isaac Seymour
@isaacseymour
The Mongoid adapter is semi-unsupported - no-one at GC knows Mongo/Mongoid that well and it was contributed by someone else (I can't entirely remember who - the PR shouldn't be too hard to find though), so I'm not sure how much help you'll be able to get in here on Mongoid adapter issues, sorry!
Damien Hogan
@damienh
Thats ok. I have an implementation semi working.

Things like

Order.in_state(:cancelled) # => [#<Order id: "123">]
Order.not_in_state(:checking_out) # => [#<Order id: "123">]

I am assuming are part of include Statesman::Adapters::ActiveRecordTransition

Isaac Seymour
@isaacseymour
Ah, I have no idea if they're implemented for Mongoid at all
for AR they're implemented in Statesman::Adapters::ActiveRecordQueries (which you would include into Order)
Damien Hogan
@damienh
Hey sorry just another question. Iv noticed that my after_transitions callbacks are being ignored or skipped within the app. When I transition between states in rails console the info I set is being applied, however whenever I do this inside the controller it sets the state fine but not the data within the call backs. Anyone come cross this before?
Damien Hogan
@damienh
ignore me resolved :)
Stuart Terrett
@shterrett
Is there a way to allow transition_to calls to be idempotent so that we don't have to check if an object is already in a certain state before transitioning?
Weston Triemstra
@thermistor
@shterrett aren't they already?
Stuart Terrett
@shterrett
@thermistor they're idempotent in that nothing changes, but they return false. Which means that if I'm switching on the result of the transition, I first have to check in_state? and then transition_to
Weston Triemstra
@thermistor
@shterrett to solve that you can add the current state as possible transition, allowing it to transition to itself, then it returns true
Eg. in your state machine model:
if pending is the state that you want to be able to transition to idempotently and return true:
transition from: :pending, to: [:pending, :finished]
Steve Bissett
@stevebissett
Is this still used as a form of communication?