Skip to content

Commit 4827110

Browse files
Add timezone to Oban Integration (#862)
Co-authored-by: Andrea Leopardi <[email protected]>
1 parent 3b3ff64 commit 4827110

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

Diff for: lib/sentry/integrations/oban/cron.ex

+9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ defmodule Sentry.Integrations.Oban.Cron do
8989

9090
defp job_to_check_in_opts(job, config) when is_struct(job, Oban.Job) do
9191
monitor_config_opts = Sentry.Config.integrations()[:monitor_config_defaults]
92+
monitor_config_opts = maybe_put_timezone_option(monitor_config_opts, job)
9293

9394
monitor_slug =
9495
case config[:monitor_slug_generator] do
@@ -170,6 +171,14 @@ defmodule Sentry.Integrations.Oban.Cron do
170171
end
171172
end
172173

174+
defp maybe_put_timezone_option(opts, %{meta: %{"cron_tz" => tz}} = _job) do
175+
Keyword.put(opts, :timezone, tz)
176+
end
177+
178+
defp maybe_put_timezone_option(opts, _job) do
179+
opts
180+
end
181+
173182
defp duration_in_seconds(%{duration: duration} = _measurements) do
174183
duration
175184
|> System.convert_time_unit(:native, :millisecond)

Diff for: test/sentry/integrations/oban/cron_test.exs

+13-10
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ defmodule Sentry.Integrations.Oban.CronTest do
135135
"type" => "interval",
136136
"value" => 1,
137137
"unit" => unquote(expected_unit)
138-
}
138+
},
139+
"timezone" => "Europe/Rome"
139140
}
140141

141142
send(test_pid, {ref, :done})
@@ -150,7 +151,7 @@ defmodule Sentry.Integrations.Oban.CronTest do
150151
job: %Oban.Job{
151152
worker: "Sentry.MyWorker",
152153
id: 942,
153-
meta: %{"cron" => true, "cron_expr" => unquote(frequency)}
154+
meta: %{"cron" => true, "cron_expr" => unquote(frequency), "cron_tz" => "Europe/Rome"}
154155
}
155156
})
156157

@@ -179,7 +180,8 @@ defmodule Sentry.Integrations.Oban.CronTest do
179180
"schedule" => %{
180181
"type" => "crontab",
181182
"value" => "* 1 1 1 1"
182-
}
183+
},
184+
"timezone" => "Europe/Rome"
183185
}
184186

185187
send(test_pid, {ref, :done})
@@ -194,7 +196,7 @@ defmodule Sentry.Integrations.Oban.CronTest do
194196
job: %Oban.Job{
195197
worker: "Sentry.MyWorker",
196198
id: 942,
197-
meta: %{"cron" => true, "cron_expr" => "* 1 1 1 1"}
199+
meta: %{"cron" => true, "cron_expr" => "* 1 1 1 1", "cron_tz" => "Europe/Rome"}
198200
}
199201
})
200202

@@ -226,7 +228,8 @@ defmodule Sentry.Integrations.Oban.CronTest do
226228
"schedule" => %{
227229
"type" => "crontab",
228230
"value" => "* 1 1 1 1"
229-
}
231+
},
232+
"timezone" => "Europe/Rome"
230233
}
231234

232235
send(test_pid, {ref, :done})
@@ -239,7 +242,7 @@ defmodule Sentry.Integrations.Oban.CronTest do
239242
job: %Oban.Job{
240243
worker: "Sentry.MyWorker",
241244
id: 942,
242-
meta: %{"cron" => true, "cron_expr" => "* 1 1 1 1"}
245+
meta: %{"cron" => true, "cron_expr" => "* 1 1 1 1", "cron_tz" => "Europe/Rome"}
243246
}
244247
})
245248

@@ -265,7 +268,7 @@ defmodule Sentry.Integrations.Oban.CronTest do
265268
job: %Oban.Job{
266269
worker: "Sentry.MyWorker",
267270
id: 123,
268-
meta: %{"cron" => true, "cron_expr" => "@daily"}
271+
meta: %{"cron" => true, "cron_expr" => "@daily", "cron_tz" => "Europe/Rome"}
269272
}
270273
})
271274

@@ -293,14 +296,14 @@ defmodule Sentry.Integrations.Oban.CronTest do
293296
worker: "Sentry.ClientWorker",
294297
id: 123,
295298
args: %{"client" => client_name},
296-
meta: %{"cron" => true, "cron_expr" => "@daily"}
299+
meta: %{"cron" => true, "cron_expr" => "@daily", "cron_tz" => "Europe/Rome"}
297300
}
298301
})
299302

300303
assert_receive {^ref, :done}, 1000
301304
end
302305

303-
test "custom options", %{bypass: bypass} do
306+
test "custom options overide job metadata", %{bypass: bypass} do
304307
test_pid = self()
305308
ref = make_ref()
306309

@@ -339,7 +342,7 @@ defmodule Sentry.Integrations.Oban.CronTest do
339342
worker: inspect(WorkerWithCustomOptions),
340343
id: 123,
341344
args: %{},
342-
meta: %{"cron" => true, "cron_expr" => "@daily"}
345+
meta: %{"cron" => true, "cron_expr" => "@daily", "cron_tz" => "America/Chicago"}
343346
}
344347
})
345348

0 commit comments

Comments
 (0)