Hi everyone!
I need a guidance for using context or action inputs or something like that.
I defined a function that calls an action.
define :delete_and_disconnect_integrations,
action: :delete_and_disconnect_integrations
And two actions in different resources. One uses another one
destroy :delete_and_disconnect_integrations do
soft? true
require_atomic? false
change set_attribute(:deleted_at, &DateTime.utc_now/0)
change cascade_update(:token, action: :clear_and_disconnect)
change Project.Context.Changes.Disconnect1
end
update :clear_and_disconnect do
require_atomic? false
change set_attribute(:token, nil)
change Project.Context.Changes.Disconnect2
end
It updates two tables using cascade_update
but also it calls an extenral API request for every table record. In case if the token is invalid I don’t need to call to an external API and I need to just update the db. I was considering adding a parameter to skip API calls like that:
Project.Context.delete_and_disconnect_integrations(
struct.id,
tenant: tenant.id,
context: %{skip_api_calls: true}
)
And I can fetch it via Map.get(changeset.context, :skip_api_calls, false)
in Disconnect1
but it isn’t available in Disconnect2
.
How would you solve such problems in general?