diff --git a/app/jobs/cron/datagouv/file_by_month_job.rb b/app/jobs/cron/datagouv/file_by_month_job.rb new file mode 100644 index 000000000..723a48af3 --- /dev/null +++ b/app/jobs/cron/datagouv/file_by_month_job.rb @@ -0,0 +1,19 @@ +class Cron::Datagouv::FileByMonthJob < Cron::CronJob + include DatagouvCronSchedulableConcern + self.schedule_expression = "every month at 3:00" + FILE_NAME = "nb_dossiers_crees_par_mois" + + def perform(*args) + GenerateOpenDataCsvService.save_csv_to_tmp(FILE_NAME, data) do |file| + begin + APIDatagouv::API.upload(file, :statistics_dataset) + ensure + FileUtils.rm(file) + end + end + end + + def data + Dossier.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + end +end