Skip to content

Commit

Permalink
ImportDatasetMonthlyMetricsJob : mise à jour updated_at (#3699)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Jan 2, 2024
1 parent 7b644bc commit 14d9d74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions apps/transport/lib/jobs/import_dataset_monthly_metrics_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ defmodule Transport.Jobs.ImportDatasetMonthlyMetricsJob do
dataset_datagouv_id
) do
Enum.each([{:views, monthly_visit}, {:downloads, monthly_download_resource}], fn {metric_name, count} ->
count = count || 0

%DB.DatasetMonthlyMetric{}
|> DB.DatasetMonthlyMetric.changeset(%{
dataset_datagouv_id: dataset_datagouv_id,
year_month: metric_month,
metric_name: metric_name,
count: count || 0
count: count
})
|> DB.Repo.insert!(
conflict_target: [:dataset_datagouv_id, :year_month, :metric_name],
on_conflict: {:replace, [:count]}
on_conflict: [set: [count: count, updated_at: DateTime.utc_now()]]
)
end)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ defmodule Transport.Test.Transport.Jobs.ImportDatasetMonthlyMetricsTestJob do
dataset_datagouv_id: ^datagouv_id,
year_month: "2023-12",
metric_name: :views,
count: 1337
count: 1337,
inserted_at: inserted_at,
updated_at: updated_at
},
# Has been inserted
%DB.DatasetMonthlyMetric{
Expand All @@ -113,6 +115,9 @@ defmodule Transport.Test.Transport.Jobs.ImportDatasetMonthlyMetricsTestJob do
count: 43
}
] = DB.Repo.all(DB.DatasetMonthlyMetric)

# `updated_at` has been updated to reflect that this row has changed
assert DateTime.after?(updated_at, inserted_at)
end
end

Expand Down

0 comments on commit 14d9d74

Please sign in to comment.