From 9fa54c3cc8c2596a891960643f65d35f06b14516 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Wed, 29 Jun 2022 12:09:21 +0200 Subject: [PATCH] =?UTF-8?q?Nombre=20de=20d=C3=A9marches=20cr=C3=A9=C3=A9s?= =?UTF-8?q?=20par=20mois=20:=20CRON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cron/datagouv/procedure_by_month_job.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/jobs/cron/datagouv/procedure_by_month_job.rb diff --git a/app/jobs/cron/datagouv/procedure_by_month_job.rb b/app/jobs/cron/datagouv/procedure_by_month_job.rb new file mode 100644 index 000000000..1327c4ff3 --- /dev/null +++ b/app/jobs/cron/datagouv/procedure_by_month_job.rb @@ -0,0 +1,19 @@ +class Cron::Datagouv::ProcedureByMonthJob < Cron::CronJob + include DatagouvCronSchedulableConcern + self.schedule_expression = "every month at 3:00" + FILE_NAME = "nb_procedures_creees_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 + Procedure.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + end +end