You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@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.
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.
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.
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.
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.
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.
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.
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.
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.
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..
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.
Activity
wolflu05 commentedon Aug 18, 2022
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.
miggland commentedon Aug 18, 2022
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.
matmair commentedon Aug 21, 2022
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.
wolflu05 commentedon Aug 22, 2022
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,BarcodeMixinorLocate 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
SettingsMixinfor storing settings. Each instance could have aget_unique_identifiermethod which can be used to write files to disk with a unique identifier.2.
MultipleSettingsMixinA second idea is to have a different Settings mixing which supports multiple Configurations. This would then require the
print_labelmethod (e.g. for theLabelPrintingMixin) to have some kind of which configuration function parameter which can then be used for theget_settingmethod. This approach would need to be implemented in each Mixin which should support multi config somehow.📫 Answers
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)
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 theLabelPrintingMixinto allow the plugin to expose multiple printers.posted by @matmair in #3555 (comment)
Then this would also be needed. How is this possible?
wolflu05 commentedon Sep 8, 2022
I don't want to push someone, but this issue needs also some labels.
github-actions commentedon Nov 8, 2022
This issue seems stale. Please react to show this is still important.
wolflu05 commentedon Nov 8, 2022
I think this is not stale. I listed out several methods to globally solve this issue.
matmair commentedon Nov 8, 2022
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.
github-actions commentedon Jan 8, 2023
This issue seems stale. Please react to show this is still important.
5 remaining items
wolflu05 commentedon Mar 27, 2023
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.
matmair commentedon Mar 27, 2023
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.
wolflu05 commentedon Mar 28, 2023
So rename this issue or create a new one?
matmair commentedon Mar 30, 2023
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.
wolflu05 commentedon Mar 30, 2023
This can't be handled by the plugin currently, as there is no option to expose multiple printers by one plugin.
miggland commentedon Mar 31, 2023
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..
wolflu05 commentedon May 5, 2023
@matmair , @SchrodingersGat what is the goal on solving this issue? I want to know that before I start rewriting my cups plugin.
SchrodingersGat commentedon May 5, 2023
No action or plan on this currently
wolflu05 commentedon May 6, 2023
And what would you suggest to do?
SchrodingersGat commentedon May 7, 2023
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.
wolflu05 commentedon May 7, 2023
Im currently writing something, but have no time, I'll post that later.
wolflu05 commentedon May 7, 2023
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.