Get settings from other addon

I’m creating a server addon for the first time and I’m running into a wall. I want to get the project settings of another addon than the one I’m developing. I’m not sure how to approach this. When you call self.get_studio_settings you only get the settings for the current addon but I want to query the settings for the core addon

Should I make a custom postgres call? I’m quite new to that.

Hope someone can point me in the right direction.

Thanks!

Ralph

There is no easy answer to your question. It is needed to know full context of what are you doing and where you want to access core addon settings.

To get settings of other addon you can use AddonLibrary but you have to know which version of the addon you want to get, and what settings variant you want to get (“production”, “staging” or any of develop bundles).

This practically means that you can get settings of other addon in specific cases like actions or custom endpoints, where you can get information about variant, with variant you can find bundle that is used for the settings variant from which you can get which version is used. But if you want to get other addon settings to e.g. use them in your settings then it is semi-possible, but you have know how the server backend works which is beyond short answer on forum (at least for me) still will have some caviads.

from ayon_server.addons.library import AddonLibrary

addon_name = "..."
addon_version = "..."
variant = "..."
addon = AddonLibrary.addon(
    addon_name,
    addon_version,
)
settings_model = await addon.get_studio_settings(variant)
...

Could you elaborate more?
Does this other addon belong to the current bundle (the selected bundle when starting AYON launcher) or another bundle or even not in a bundle?

Usually for testing I get current bundle settings as in ayon-recipes/get_bundle_settings_addons_info.py at be89caad3cf7748d6531d74ea1acb9975b644d40 · MustafaJafar/ayon-recipes · GitHub

Hi,

I currently have this. It works but not sure it is the desired way:


from ayon_server.addons import AddonLibrary

addon_library = AddonLibrary.getinstance()
core_addon = addon_library.get("core") settings = await core_addon.latest.get_project_settings(project_name

)

I’m looking into automatically create the project folder structure once a project on Ayon is created. I’m using the event system but found out the server can’t create folders on the network drive. Makes sense but for me it’s the first time to work on the server side.

So I have to go back to the drawing board anyway. Looking into webactions now.

Thanks for your help!

Cheers,

Ralph

Besides web actions, you can rely on services. you’d need to mount the project storage to the service.

Right…

I need to look into services and how they’re set up. I do have ash running. Still not 100% wrapped my head around it how they work and setup.

I think that would be a better option than web actions

Thanks!

Ralph

2 Likes

I guess as a start you can check existing services in different addons such as kitsu, ftrack, and etc.

Mostly, we have 2 folders in repos:

  1. “services”: where services implementation live. (basically, they are all python scripts + docker file for builder docker image where the code will run eventually)
  2. “service tools”: which includes helper tools for development like asking it to run a particular service.

I didn’t dig much in creating services before, but let me share some findings. Hope it helps wrapping your head around it.

Personally, as a start, I believe for a far very minimal service, one can start by writing their python implementation.

Here’s a very rough example which should outline the code flow.

Rough example
import ayon_api


def main_loop():
    # while service is not stopped
    ...

def main():
    try:
        ayon_api.init_service()
        connected = True
    except Exception:
        connected = False

    if not connected:
        ...

    # Register interrupt signal (it includes a clean up process)
    ...

    main_loop()


if __name__ == "__main__":
    main()

once this is setup, one can start exploring working with events:

from ayon_api import (
    get_event,
    get_events,
    update_event,
    dispatch_event,
    create_event,
    delete_event,
    enroll_event_job,
)

I don’t think there’s a way to subscribe to events to act upon them in Realtime. Alternatively, I think it’s the other where you implement a listener and just check the server events periodically for the event of interest.


Tip: In addon server side you can implement a web hook to be run when a specific event is created. (which sounds like subscribing to events)

Register Event Hook
class MyCooolAddon(BaseServerAddon):
  async def setup(self):
    register_event_hook("entity.folder.created", self.on_folder_created)

  async def on_folder_created(self, event):
    """put a comment on every new folder"""

    await create_activity(
        project_name=event.project, 
        activity_type="comment", 
        body=f"Hoooo, i have been created by f{event.user}!", 
        entity_references=[
         {"type": "origin", "entity_type": "folder", "entity_id": event.summary["folderId"}
        ]
        user_references=[{"type": "author", "name": event.user}]
     )

You can also stop listening via:

# Stop listen
event_callback.deregister()