-
-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin system #1279
Comments
what is the difference between your suggestion and |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Adding another hook to run code, plugins, or modules before If something is missing in initializers, we can improve it, but introducing another hook feels unnecessary. |
For example a plugin for correctly/better loading env variables. Also a plugin might want to use both. Now the user would need to modify their main method and add one or more initializers to their local hooks which is prone to user error and adding/removing an initializer would always be a breaking change Things like registering tasks and worker or tables that need to be truncated is not even possible with This "Hook" does not need to be complicated just expose the normal Hooks to plugin so that these things are possible for the maintainer to do not the user. |
Will boot work with env loading? Also adding another hook would not be that complicated. My goal is that the user just needs to say "load that plugin" and the plugin then does the rest. |
The Let's look at a real example of a plugin you want to implement and see how we can integrate it using the existing hooks. do you want to give one? |
Currently I cannot show my plugins I've already made.
So for example in my Env Plugin I've done something like this: async fn load_config(env: &Environment) -> Result<Config> {
// Other stuff..
EnvLoading::load_from_env(env);
env.load()
}
fn register_tasks(tasks: &mut Tasks) {
EnvLoading::register_commands(&mut tasks);
// tasks-inject (do not remove)
} And this is a simple plugin. I currently making plans to propose an enhance event/message system which I want to make as a plugin first. async fn load_config(env: &Environment) -> Result<Config> {
EventSystem::before_boot(env);
MessageSystem::before_boot(env);
env.load()
}
async fn boot(mode: StartMode, environment: &Environment, mut config: Config) -> Result<BootResult> {
config = EventSystem::update_config(config);
config = MessageSystem::update_config(config);
create_app::<Self, Migrator>(mode, environment, config).await
}
async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
Ok(vec![
Box::new(EventSystem::initializer()),
Box::new(MessageSystem::initializer())
])
}
async fn connect_workers(ctx: &AppContext, queue: &Queue) -> Result<()> {
// Yeah I think you get it
Ok(())
}
// Also some things need to be done in: register_tasks, truncate, after_context Which is absolutely not feasible for the user. And this are just my basic Plan for the 0.1.0 I've not even started developing or extended features. |
Following your example:
If you can provide a GitHub repository with your setup, I’d be happy to review it and suggest improvements to enhance your implementation and better understand the problem. |
When I take a look at ever symfony, spring, ruby etc. projects they all use a lot of third-party extensions but no-one is required to manage that much of custom code for EVERY extension because they all provide some kind of enhanced Plugin system. Also i would replace the unstructured settings with a place for custom .yaml files like mentioned above. I don't currently have a Repo atleast none with code just a bunch of markdown files with concepts. But maybe a better description would be a Plugin system. |
So with the example. And the initializer works fine but try adding a truncate specific db command. |
What prevents you from reading the config in the initializer? |
Nothing And this still doesnt solve the other problems |
I think it's opinionated, and I don't currently see enough value |
Yes ofcourse. For example when I take a look at my symfony config files. But yes thats why I am open for discussions but this isn't my big point |
Feature Request
Is your feature request related to a problem? Please describe.
I wrote a few "plugins" for loco for some projects and I've noticed that there is no real documentation or features on how to do that.
Describe the solution you'd like
Disclaimer: I use packages and plugins interchangeably. What name gets used does not really matter as long as it is consistent.
My Solution would be the following (inspired by symfony and their packages/bundles):
Configuration
Document a config folder where custom config should be located.
I thought about something like
config/packages
(which I would prefer but it doesn't really matter) orconfig/plugins
Example:
config/packages/my-plugin.yaml
Also I would expose a config that loads a config into a struct just like locos configuration with env resolving, etc.
Example:
Which would automatically resolves the
config/packages
folder structure.Also I have considered that plugins should could extend the normal config.yaml but this could lead to name conflicts.
The other method is ofcourse not immune to it but it would reduce the chance.
Also having more then one config increases the readability if correctly used.
Plugin registration hook?
Maybe a hook that just exposes the normal AppHooks to the plugin so that the user would not need to write for example every initializer themselfs into the hook.
So for example:
or something like this what would reduce the acutal lines of code to one.
And the plugin maintainer has more control which would result in less user error.
Disclaimer: This should just point out the structure I guess that the rest is complete non-sense.
Documentation
Ofcourse all this needs to be documented and maybe an example plugin or a template repository would be great.
Describe alternatives you've considered
Doing it myself for every package but thats kinda annoying.
I just don't like copying code.
Misc
This is more of a concept/discussion.
I definitely forgot something so I will probably add more to it over time.
If you like this idea and this concept is more thought through I would contribute it.
The text was updated successfully, but these errors were encountered: