Question about Structured Job in Oban

I have to process/1 function in my worker and also have args_schema is defined.

  args_schema do
    field :post_id, :uuid, required: true
    field :user_id, :uuid, required: true
    field :comment_id, :uuid

def process(%Job{args: %{post_id: post_id, user_id: user_id, comment_id: comment_id}}) do
  # other code
  %{comment_ids: ids}
  |> new()
  |> Oban.insert()
end

def process(%Job{args: %{comment_ids: ids}}) do
  # code here.
end

I guess second process/1 function is not called and get warning about unknown field. How can I do this? Can I define another args_schema before second process function? or this is not possible?

Hey @freewebwithme args_schema is defining a struct, and you can only have one struct definition per module. Your args_schema defines a :comment_id field not a :comment_ids field.

It sounds like you just have two different jobs? Alternatively, just use :comment_ids instead of :comment_id and when you only have one just have it like comment_ids: [comment.id]

2 Likes