How to run daily schedule Oban job and and send email to customer at the schedule time

Please I need help, I want to run a daily schedule Oban job every midnight and I want to schedule the email to be sent to the customer in the morning by 10 a.m. But am confused with the approach and I want to confirm if am doing the right thing.

@impl Oban.Worker
  def perform(%Oban.Job{args: _args}) do
    Logger.info("begin processing deliverables reminder job")

    Milestone.get_milestones_3_days_before_due_date()
    |> Stream.map(
      &(convert_milestone(&1)
        |> new(priority: 2, scheduled_at: DateTime.shift_zone!(DateTime.add(DateTime.utc_now(), 2, :minute), "Etc/UTC")))
    )
    |> Stream.chunk_every(@chunk_size)
    |> Task.async_stream(&Oban.insert_all/1, ordered: false, timeout: @timeout_ms, on_timeout: :kill_task)
    |> Stream.filter(&(&1 == {:exit, :timeout}))
    |> Enum.count()
    |> IO.inspect()
  end

The above snippet is how am handling the daily schedule job. But where am confused is how will I trigger the email service that will be sent to the customer by 10 a.m. after when the job already ran at midnight.

Look at the Oban Cron plugin.

https://hexdocs.pm/oban/Oban.Plugins.Cron.html

2 Likes