Skip to content

[FR] Create multiple instances of a plugin #3568

Closed as not planned
Closed as not planned

Description

@wolflu05

I agree it's not easy, but I can't see that it'll be a problem for plugin developers (who as a programmer assumes their code will only ever run in one instance??). I think putting multiple configurations in each plugin is the wrong way to go, meaning each plugin developer will have to solve the same problem...

I can fully agree to that. I think this is a problem where every plugin developer has to deal with. What about defining an option ALLOW_MULTIPLE_INSTANCES next to name, slug and description as plugin class variable? So the developer can say no, my plugins may interfer with each other if there are multiple instances. Or no, they might work fine with different configs. Otherwise each plugin developer has to implement the AppMixin to create some kind of array system which holds different configs as it's not possible with the SettingsMixin. And even if it would be possible, I think it's much easier for a developer to just set a ALLOW_MULTIPLE_INSTANCES = True and not deal every time with the same problem.

These are my thoughts on this topic and I think, this issue needs to be reopened.

Originally posted by @wolflu05 in #3555 (comment)

@matmair, you're right with locking, #3555 is the wrong place for this discussion, sorry just wanted to give my thoughts and also answer SchrodingersGat. This is a generic discussion about multiple simulations instances of a plugin and not specific to a plugin now, so inventree/inventree is the right place.

Activity

  1. wolflu05 commented on Aug 18, 2022

    @wolflu05
    MemberAuthor

    Our target audience for plugins is the general user base. Plugins should be easy to create and share even for ppl. not to familiar with debian. That is why there are so many domain-specific mixins: do keep the plugins small and easy to understand. The goal is an octoprint-like plugin scene in which InvenTree is the reliable base but plugins solve niche problems.

    Originally posted by @matmair in #3555 (comment)

    This would only underline this FR. A general system where plugins can be added multiple times to keep the plugins itself simpler.

  2. miggland commented on Aug 18, 2022

    @miggland
    Contributor

    Thanks @wolflu05, this is a better way to express the issue - as it is a general problem that each plugin has only single configuration, and is called with a single profile parameter locked to a certain configuration.

  3. matmair commented on Aug 21, 2022

    @matmair
    Member

    I am in strong disagreement and think it will make understanding and debugging plugins much harder.
    But if you have a working PoC that is not breaking the system on multi-instance container setups (problem: state synchronisation while adding new instances) and still works with plugins that use file based configs I do not see why this won't be merged.

    On a more general note: the plugin system in its design is not targeted towards django pros (except the AppMixin) but regular python programmers that wish to extend certain functions. Plugins should be small single purpose code snippets that can be easily shared with others to tweak InvenTree instances.

  4. wolflu05 commented on Aug 22, 2022

    @wolflu05
    MemberAuthor

    I think just to keep things simple it would be necessary to solve this problem generally. I think this only makes sense to all none integration plugins. E.g. LabelPrintingMixin, BarcodeMixin or Locate Mixin.

    💡 Ideas

    I have two ideas of how this could work:

    1. Load plugin multiple times with different configs

    If the plugin developer sets a specific class variable we know, that there could be multiple instances of this plugin. This limits the developer to use the SettingsMixin for storing settings. Each instance could have a get_unique_identifier method which can be used to write files to disk with a unique identifier.

    2. MultipleSettingsMixin

    A second idea is to have a different Settings mixing which supports multiple Configurations. This would then require the print_label method (e.g. for the LabelPrintingMixin) to have some kind of which configuration function parameter which can then be used for the get_setting method. This approach would need to be implemented in each Mixin which should support multi config somehow.

    📫 Answers

    (problem: state synchronisation while adding new instances)

    I don't think we should care about this more than its currently. Because if a plugin currently uses a file you also have to care on your own to sync these files (e.g. via ceph) on your own. Same applies to inventree files (e.g. media files)

    But if you have a working PoC that is not breaking the system on multi-instance container setups [...] I do not see why this won't be merged.

    Sorry, but I think Im the wrong for implementing this.

    ⏲️ About the current state

    Just for the current state, if I would try to implement multiple printers in one plugin, this is not possible. We would need some king of get_printers() method in the LabelPrintingMixin to allow the plugin to expose multiple printers.


    it takes 4 lines to create multiarray settings.

    posted by @matmair in #3555 (comment)

    Then this would also be needed. How is this possible?

  5. wolflu05 commented on Sep 8, 2022

    @wolflu05
    MemberAuthor

    I don't want to push someone, but this issue needs also some labels.

  6. added
    question
    plugin
    roadmap
    on Sep 8, 2022
  7. github-actions commented on Nov 8, 2022

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  8. added
    inactive
    on Nov 8, 2022
  9. wolflu05 commented on Nov 8, 2022

    @wolflu05
    MemberAuthor

    I think this is not stale. I listed out several methods to globally solve this issue.

  10. removed
    inactive
    on Nov 8, 2022
  11. self-assigned this
    on Nov 8, 2022
  12. matmair commented on Nov 8, 2022

    @matmair
    Member

    This is not a high priority for me right now. I am assigning it to me to stop it from going stale permanently - If someone else is actively interested in creating a PR: feel free or ping me to get assigned.

  13. github-actions commented on Jan 8, 2023

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  14. 5 remaining items

  15. added
    inactive
    on Mar 23, 2023
  16. wolflu05 commented on Mar 27, 2023

    @wolflu05
    MemberAuthor

    What should we do with this @matmair there is no option to connect two printers with the same plugin. This would need some kind of a copy of the plugin with a different slug, but this solution is very ugly.

  17. removed
    inactive
    on Mar 27, 2023
  18. matmair commented on Mar 27, 2023

    @matmair
    Member

    As stated before: I am not a fan of the complications multiple instances of a plugin bring regarding state management - we already have enough edge cases with caching. I think this should be handled by the printer plugin itself.

  19. wolflu05 commented on Mar 28, 2023

    @wolflu05
    MemberAuthor

    So rename this issue or create a new one?

  20. matmair commented on Mar 30, 2023

    @matmair
    Member

    I think create a new one in the affected printer plugin? I do not think InvenTree should support the requested feature. Interested in the opinion of others from @inventree/triage though before ruling it out. My stance is that it adds too much complexity.

  21. wolflu05 commented on Mar 30, 2023

    @wolflu05
    MemberAuthor

    This can't be handled by the plugin currently, as there is no option to expose multiple printers by one plugin.

  22. miggland commented on Mar 31, 2023

    @miggland
    Contributor

    As @wolflu05 points out, this can't be handled by the plugin. Also, I am convinced this doesn't only apply to printers - there will be other cases where the same plugin will be wanted, but with different settings.

    Furthermore: even if the plugin where rewritten, there is no option to pass a choice of printer to the plugin when printing. Currently, printing a label allows/requires choosing a certain printer plugin - do you really prefer changing the core to checking if the chosen plugin shows multiple printers as well? This sounds very complicated - and would only solve the issue for printing. The next special case is bound to follow..

  23. wolflu05 commented on May 5, 2023

    @wolflu05
    MemberAuthor

    @matmair , @SchrodingersGat what is the goal on solving this issue? I want to know that before I start rewriting my cups plugin.

    1. Allow plugins to be enabled multiple times with different settings => requires a general plugin overhaul
    2. Each printer plugin needs to handle multiple printers themself => requires adjustment so that a printing plugin can expose multiple printers
  24. SchrodingersGat commented on May 5, 2023

    @SchrodingersGat
    Member

    No action or plan on this currently

  25. wolflu05 commented on May 6, 2023

    @wolflu05
    MemberAuthor

    And what would you suggest to do?

  26. SchrodingersGat commented on May 7, 2023

    @SchrodingersGat
    Member

    I think the cleanest implementation here is to allow printing plugins to expose multiple printers (if they want to). Currently the list of available printers is simply the list of available printing plugins. But we could add a method to enumerate multiple printers, and add those to the list presented to the user. Each plugin would be responsible for uniquely identifying the printers.

  27. wolflu05 commented on May 7, 2023

    @wolflu05
    MemberAuthor

    Im currently writing something, but have no time, I'll post that later.

  28. wolflu05 commented on May 7, 2023

    @wolflu05
    MemberAuthor

    I think we can close this now as not planned. The initial idea of having multiple instances is no good option to solve that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pluginquestionroadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions