Hello!
Does anyone know how best to/have some advice on retrieving addon settings via project/studio while handling an event via EventStream.subscribe()? I cannot find documentation on the ayon server lib (Server addon)
Hello!
Does anyone know how best to/have some advice on retrieving addon settings via project/studio while handling an event via EventStream.subscribe()? I cannot find documentation on the ayon server lib (Server addon)
This might be one for @martin.wacker to answer.
But, in the meantime.
And I suppose you’re referring to this event system Event system (developer’s documentation)?
I am using os.environ to pass json settings into the event currently (Working) as I do not have scope of BaseServerAddon without instantiating a bunch of things. I also attempted passing the BaseServerAddon class (from server/init.py) to the class housing the event handler function with no luck.
Using os.environ for this seems backward so I assume there’s a better way I’m not seeing!
So I’m not getting stuck persay as the addon ive made works, I want to understand the ayon-way rather than writing potentially hacky code to achieve the results we want!
example base of how I got it working:
class ServerAddon(BaseServerAddon):
settings_model: Type[ServerSettings] = ServerSettings
if not os.environ.get("SERVER_ADDON_SETTINGS"):
os.environ["SERVER_ADDON_SETTINGS"] = json.dumps({})
def initialize(self):
EventStream.subscribe('entity.task.status_changed', ServerAddonEventHandler.handle_event)
It would be nicer to do something like:
class ServerAddon(BaseServerAddon):
def initialize(self):
handler = ServerEventHandler()
handler.addon = self
EventStream.subscribe('entity.task.status_changed', handler.handle_event)
then call handler.addon.get_project_settings(“foo”) in the event handler class
Do i understand correctly that you want to call a method on your server addon whenever a task status is changed?
You can pass the method directly as the event handler. I’ve added a small example to ayon-example-addon.
when you play with that, you will get expected results:
2024-06-13 10:09:32 DEBUG server Example addon says, that Changed task lighting status to Pending review
2024-06-13 10:09:32 DEBUG server Admin's favorite color is red
2024-06-13 10:09:44 DEBUG server Example addon settings changed. New favorite color is green
2024-06-13 10:10:01 DEBUG server Example addon says, that Changed task compositing status to Approved
2024-06-13 10:10:01 DEBUG server Admin's favorite color is green
Please keep in mind, that handlers are executed as background tasks on the server. They will be finished AFTER the response to the original request is sent and they should be lightweight - if there’s anything you can cache, cache it (there’s aiocache module available on the server btw) and keep heavy-lifting on services
Thanks @martin.wacker - You’re correct in your assumptions, I’m looking to have the project_settings/studio settings available inside the event call. This is a much cleaner solution. I’ll give this a go. The update to the template addon is very much appreciated too.