0

There are a few popular Ruby state machine gems such as geekq/workflow and aasm. Are they thread safe in multi-tenant Rails 4.2 application?

I am using geekq/workflow which defines process definition on model class as class method. This makes me wonder if other users who login late will overwrite the previous users workflow definition.

Can some developer comment on the thread safe issue of state machine? Or recommend a state machine gem which is thread-safe in multi-tenant Rails app?

halfer
  • 19,824
  • 17
  • 99
  • 186
user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

1

Those gems are designed to let you-the-developer define a workflow or state machine, where the possible states and the way they transition is the same for everyone. If that's what you're doing, then regardless of tenant, the workflow is set up at the beginning and never changes, and they are fine for multi-threaded, multi-tenant apps.

If you are letting your users define workflows, I think they are simply not the right tool.

Paul A Jungwirth
  • 23,504
  • 14
  • 74
  • 93
  • 1
    Then you should be fine. The `workflow` gem does its setup when the ActiveRecord class is first loaded, so tenants/threads shouldn't be an issue. – Paul A Jungwirth Mar 24 '16 at 17:57
  • Did you mean `workflow` is defined only once in a model for one user and never be changed late during the user session? – user938363 Mar 24 '16 at 22:07
  • No, I mean when the model *class* is loaded, the possible states and their transitions are defined. Each model *instance* has its own state, saved in the database. Even the instances' state doesn't depend on a user's session in any way. – Paul A Jungwirth Mar 25 '16 at 04:38
  • `Paul A Jungwirth`, I am struggling to find a way to load workflow def in model `after` a user logs in. Do you have any suggestion about how to do that? Many thanks. – user938363 Mar 31 '16 at 04:19