From d5f4e591f9cfedefdd4a71515b46c78e9a77e2ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= <ismael.bouya@normalesup.org>
Date: Sat, 21 Apr 2018 01:09:28 +0200
Subject: Add redis to cryptoportfolio

---
 modules/role/manifests/cryptoportfolio.pp          |  4 +++
 modules/role/manifests/cryptoportfolio/bot.pp      | 31 ++++++++++++++++++++++
 .../cryptoportfolio/bot_config_hourly.ini.erb      | 17 ++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb

(limited to 'modules/role')

diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp
index 6a659cc..53b7abd 100644
--- a/modules/role/manifests/cryptoportfolio.pp
+++ b/modules/role/manifests/cryptoportfolio.pp
@@ -9,6 +9,7 @@ class role::cryptoportfolio (
   String            $pg_db,
   Optional[String]  $pg_hostname          = "localhost",
   Optional[String]  $pg_port              = "5432",
+  Optional[String]  $redis_host           = "/run/redis/redis.sock",
   Optional[String]  $web_host             = undef,
   Optional[String]  $web_port             = "",
   Optional[Boolean] $web_ssl              = true,
@@ -30,6 +31,9 @@ class role::cryptoportfolio (
   contain "role::cryptoportfolio::notify"
 
   unless empty($trader_version) {
+    if versioncmp($trader_version, "v1.3") >= 0 {
+      include "profile::redis"
+    }
     contain "role::cryptoportfolio::bot"
   }
 
diff --git a/modules/role/manifests/cryptoportfolio/bot.pp b/modules/role/manifests/cryptoportfolio/bot.pp
index 082e820..2f01c98 100644
--- a/modules/role/manifests/cryptoportfolio/bot.pp
+++ b/modules/role/manifests/cryptoportfolio/bot.pp
@@ -3,6 +3,7 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
 
   $cf_bot_app = "${home}/bot"
   $cf_bot_app_conf = "${home}/bot_config.ini"
+  $cf_bot_app_conf_hourly = "${home}/bot_config_hourly.ini"
   $cf_bot_app_reports = "${home}/bot_reports"
 
   ensure_packages(["python", "python-pip"])
@@ -80,6 +81,36 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
     ],
   }
 
+  if versioncmp($trader_version, "v1.3") >= 0 {
+    file { $cf_bot_app_conf_hourly:
+      owner   => $user,
+      group   => $group,
+      mode    => "0600",
+      content => template("role/cryptoportfolio/bot_config_hourly.ini.erb"),
+      require => [
+        User["$user:"],
+        Archive["${home}/trader_${trader_version}.tar.gz"],
+      ],
+    }
+
+    cron::job::multiple { "py-cryptoportfolio-hourly":
+      ensure      => present,
+      environment => ["HOME=${home}","PATH=/usr/bin/"],
+      require     => [
+        File[$cf_bot_app_conf_hourly],
+        Archive["${home}/trader_${trader_version}.tar.gz"]
+      ],
+      jobs        => [
+        {
+          command     => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf_hourly",
+          user        => $user,
+          minute      => 30,
+          description => "Print the current state to redis",
+        },
+      ],
+    }
+  }
+
   unless empty($webhook_url) {
     exec { "bot-slack-notify":
       refreshonly => true,
diff --git a/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb b/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb
new file mode 100644
index 0000000..067f12a
--- /dev/null
+++ b/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb
@@ -0,0 +1,17 @@
+[postgresql]
+db-host = <%= @pg_hostname %>
+db-port = <%= @pg_port %>
+db-user = <%= @pg_user %>
+db-password = <%= @pg_password %>
+db-database = <%= @pg_db %>
+
+[redis]
+redis-host = <%= @redis_host %>
+
+[app]
+action = print_balances
+report-redis
+no-report-path
+no-report-db
+quiet
+debug
-- 
cgit v1.2.3