diff --git a/app/jobs/cron/datagouv/administrateur_by_month_job.rb b/app/jobs/cron/datagouv/administrateur_by_month_job.rb new file mode 100644 index 000000000..346b9cf90 --- /dev/null +++ b/app/jobs/cron/datagouv/administrateur_by_month_job.rb @@ -0,0 +1,19 @@ +class Cron::Datagouv::AdministrateurByMonthJob < Cron::CronJob + include DatagouvCronSchedulableConcern + self.schedule_expression = "every month at 3:00" + FILE_NAME = "nb_administrateurs_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 + Administrateur.where(created_at: 1.month.ago.beginning_of_month..1.month.ago.end_of_month).count + end +end diff --git a/config/secrets.yml b/config/secrets.yml index ffdd413cd..66c616696 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -83,6 +83,7 @@ defaults: &defaults api_url: <%= ENV['DATAGOUV_API_URL'] %> descriptif_demarches_dataset: <%= ENV['DATAGOUV_DESCRIPTIF_DEMARCHES_DATASET'] %> descriptif_demarches_resource: <%= ENV['DATAGOUV_DESCRIPTIF_DEMARCHES_RESOURCE'] %> + statistics_dataset: <%= ENV['DATAGOUV_STATISTICS_DATASET'] %> development: