Is It Possible to Track Create and Update Operations at the Domain Level for AshOban?

Hi, sorry, Is it possible to track create and update operations at the domain level of all resources under this domain, so that whenever such actions occur, their information is sent to AshOban for further processing? Something like
defmodule MishkaCms.Runtime do
use Ash.Domain,
otp_app: :mishka_cms
...

oban do
triggers do

trigger :runtime_preload_compiler do

action [:create, :update]
worker_module_name MyObanModuleWorker.RuntimeCompiler
end
end
end

...
end
defmodule MishkaCms.Runtime do
use Ash.Domain,
otp_app: :mishka_cms
...

oban do
triggers do

trigger :runtime_preload_compiler do

action [:create, :update]
worker_module_name MyObanModuleWorker.RuntimeCompiler
end
end
end

...
end
The data for example:
resource: xxx
action: create
data: xxx # after saved in database
resource: xxx
action: create
data: xxx # after saved in database
Solution:
Yeah nothing builtin to help you do that. Your best bet is likely to have custom Oban jobs for the compilation you want to do and then to use global changes to start those jobs in the same transaction on each resource.
Jump to solution
4 Replies
ZachDaniel
ZachDaniel3mo ago
No, not currently, but AshOban doesn't really work that way even at the resource level. It doesn't "trigger" off of actions, those triggers are looking for matching records and running specific update actions, with the ability to optionally trigger manually inside of actions using change run_oban_trigger() and AshOban.run_trigger() You could write an extension that modifies a resource to make it have some kind of trigger if you wanted all resources in a domain to behave a specific way It might be better to describe what you're specifically trying to do though
Shahryar
ShahryarOP3mo ago
I think your explanation was very clear. I have a domain called MishkaCms.Runtime which contains several resources. Each of these resources represents a piece of data that needs to be compiled at runtime. For example: JShoks, LiveView modules, and Phoenix components. (In some cases, I store their HTML in the database and they are lazy-loaded, meaning they only get compiled when called.) All of these resources implement create and update functions. Now, let's say I use one of these functions in any of the resources, like component or JShoks. At that point, the latest updated data should be sent to a worker, and based on a defined priority, I want to compile them sequentially using Oban. Instead of sending this data to the worker using in my action with after_action or after_transaction, I was wondering if it's possible to define something at the domain level — so that whenever a create or update happens, the data along with the resource name gets automatically sent to the worker. When I started working with Ash, I found myself much more interested in managing things at the domain level rather than performing operations directly within the resources. I also became very inclined to follow a consistent pattern that I could apply across all my files.
Solution
ZachDaniel
ZachDaniel3mo ago
Yeah nothing builtin to help you do that. Your best bet is likely to have custom Oban jobs for the compilation you want to do and then to use global changes to start those jobs in the same transaction on each resource.
ZachDaniel
ZachDaniel3mo ago
Global changes can tap into all action types so you'd just need one per resource. Well, create, update and destroy

Did you find this page helpful?