Ash Oban trigger after action

@Rebecca Le continuing from ash oban channel; getting back to this, I have
update :my_action do
set_attribute(:about_me, "Test")
end

update :update_about_me do
accept [:about_me]
change run_oban_trigger(:my_trigger)
end
update :my_action do
set_attribute(:about_me, "Test")
end

update :update_about_me do
accept [:about_me]
change run_oban_trigger(:my_trigger)
end
and
oban do
triggers do
trigger :my_trigger do
action :my_action
worker_read_action :read
scheduler_cron false
worker_module_name MyApp.Accounts.User.AshOban.Worker.MyTrigger
end
end
end
oban do
triggers do
trigger :my_trigger do
action :my_action
worker_read_action :read
scheduler_cron false
worker_module_name MyApp.Accounts.User.AshOban.Worker.MyTrigger
end
end
end

super simple, just figuring it out. But nothing happens when I run update_about_me function regarding oban trigger šŸ¤” I was expecting that action my_action was run in an oban job.
MyApp.Accounts.User.update_about_me me, %{about_me: "I love judo"}
[debug] QUERY OK db=0.2ms queue=0.1ms idle=1116.7ms
begin []
↳ Ash.Actions.Update.Bulk.run/6, at: lib/ash/actions/update/bulk.ex:240
[debug] QUERY OK source="users" db=1.4ms
UPDATE "users" AS u0 SET "about_me" = $1 WHERE (u0."id"::uuid::uuid = $2::uuid::uuid) RETURNING u0."translations", u0."id", u0."email", u0."about_me" ["Something about me", "e5e821fb-43d9-4244-8072-ae5dea8efcf7"]
↳ AshPostgres.DataLayer.update_query/4, at: lib/data_layer.ex:1533
[debug] QUERY OK db=3.7ms
commit []
↳ Ash.Actions.Update.Bulk.run/6, at: lib/ash/actions/update/bulk.ex:240
MyApp.Accounts.User.update_about_me me, %{about_me: "I love judo"}
[debug] QUERY OK db=0.2ms queue=0.1ms idle=1116.7ms
begin []
↳ Ash.Actions.Update.Bulk.run/6, at: lib/ash/actions/update/bulk.ex:240
[debug] QUERY OK source="users" db=1.4ms
UPDATE "users" AS u0 SET "about_me" = $1 WHERE (u0."id"::uuid::uuid = $2::uuid::uuid) RETURNING u0."translations", u0."id", u0."email", u0."about_me" ["Something about me", "e5e821fb-43d9-4244-8072-ae5dea8efcf7"]
↳ AshPostgres.DataLayer.update_query/4, at: lib/data_layer.ex:1533
[debug] QUERY OK db=3.7ms
commit []
↳ Ash.Actions.Update.Bulk.run/6, at: lib/ash/actions/update/bulk.ex:240
Am I still missing something?
11 Replies
ZachDaniel
ZachDaniel•3mo ago
change set_attribute(:about_me, "Test") missing change?
ken-kost
ken-kostOP•3mo ago
okay, added it, still nothing just a sec, let me try more thoroughly wait it's good now it seems, awesome šŸŽø of course it was just a silly mistake from my end 🤠
ZachDaniel
ZachDaniel•3mo ago
šŸ˜† it happens
ken-kost
ken-kostOP•3mo ago
one more question: what is worker_read_action? I can't find anything in the docs on AshOban/Oban hexdocs searching it. I'm wondering, if the first action updates a resource, could I get that updated resource in the triggered action? šŸ¤” I made a custom action and in input I found params: %{"primary_key" => %{"id" => "e5e821fb-43d9-4244-8072-ae5dea8efcf7"}} So I guess I could fetch it with that šŸ¤” but I'm wondering if the result of the first action can be the input of the triggered action
ZachDaniel
ZachDaniel•3mo ago
I'm not sure I understand. The way jobs are triggered is that they are triggered by storing the primary key
ken-kost
ken-kostOP•3mo ago
It's more likely I don't understand. šŸ˜† so if I understand correctly: first action is done, triggers oban action, oban action get's the id, does a read (presumably related to worker_read_actionand then the second oban action is executed. so does the worker make the read and sends that to the action? I'm trying to understand what goes on behind the scenes. Because I turned my oban triggered update action into a generic action and found those params but not the whole resource struct. šŸ¤” Now I could fetch my resource with input.params["primary_key"]["id"], would that be the ash way?
ZachDaniel
ZachDaniel•3mo ago
Yeah, so for generic actions, its your job to fetch the record. For update actions, it happens automatically as needed for the update action.
ken-kost
ken-kostOP•3mo ago
ah, cool, thanks for the info šŸ‘
ZachDaniel
ZachDaniel•3mo ago
We insert an oban job w/ that primary key in an after action hook, and oban triggers the job
ken-kost
ken-kostOP•3mo ago
So if I want to do an LLM prompt that does translation for instance but also process the response so that I may store the translations through AshTrans on the same resource, could I do that through an update action? šŸ¤”
ZachDaniel
ZachDaniel•3mo ago
You could store the original message with the thing that is triggering and then the update action could translate it and store the translation

Did you find this page helpful?