I have a crontab entry scheduling PocketTax.Finexer.TransactionsSyncProducer and want to show users the next time it will be run
Application.get_env(:pocket_tax, Oban)
[
repo: PocketTax.Repo,
engine: Oban.Pro.Engines.Smart,
queues: [
default: 10,
transactions_sync_producer: [limit: 1, global_limit: 1],
transactions_sync: [
limit: 20,
global_limit: [allowed: 1, partition: [meta: :workflow_name]]
]
],
plugins: [
{Oban.Plugins.Cron,
[
crontab: [
{"0 8-20/4 * * *", PocketTax.Finexer.TransactionsSyncProducer,
[queue: :transactions_sync_producer]}
]
]},
Oban.Pro.Plugins.DynamicLifeline
]
]
Right now the code is brittle.
First, I need to get the crontab plugin config with
{:crontab, entries} =
:pocket_tax
|> Application.get_env(Oban)
|> Keyword.get(:plugins)
|> Enum.find(& elem(&1, 0) == Oban.Plugins.Cron)
|> elem(1)
|> List.first()
Then I need to find crontab entry for the module of interest and extract its schedule
sync_schedule =
entries
|> Enum.find(, & elem(&1, 1) == PocketTax.Finexer.TransactionsSyncProducer)
|> elem(0)
Now I can use Oban.Cron.Expression to get the next time it will run
sync_schedule
|> Oban.Cron.Expression.parse!()
|> Oban.Cron.Expression.next_at(DateTime.utc_now())
Is there a more convenient way to do it?






















