Skip to content

Commit 238f402

Browse files
committed
refactor: App on startup to conditionally start mqtt publisher
1 parent dfc26ec commit 238f402

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/app.cr

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,21 @@ module PlaceOS::Source
5858
end
5959
end
6060

61+
# Configure the database connection. First check if PG_DATABASE_URL environment variable
62+
# is set. If not, assume database configuration are set via individual environment variables
63+
if pg_url = ENV["PG_DATABASE_URL"]?
64+
PgORM::Database.parse(pg_url)
65+
else
66+
PgORM::Database.configure { |_| }
67+
end
68+
6169
publisher_managers = [] of PublisherManager
6270

63-
publisher_managers << MqttBrokerManager.new
71+
if PlaceOS::Model::Broker.count > 0
72+
publisher_managers << MqttBrokerManager.new
73+
else
74+
puts "skipping Mqtt Broker\n"
75+
end
6476

6577
influx_host, influx_api_key = INFLUX_HOST, INFLUX_API_KEY
6678

@@ -71,14 +83,6 @@ module PlaceOS::Source
7183
publisher_managers << InfluxManager.new(influx_host, influx_api_key)
7284
end
7385

74-
# Configure the database connection. First check if PG_DATABASE_URL environment variable
75-
# is set. If not, assume database configuration are set via individual environment variables
76-
if pg_url = ENV["PG_DATABASE_URL"]?
77-
PgORM::Database.parse(pg_url)
78-
else
79-
PgORM::Database.configure { |_| }
80-
end
81-
8286
# Start application manager
8387
manager = Manager.new(publisher_managers)
8488
manager.start

0 commit comments

Comments
 (0)