diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/concerns/webhookable.rb b/app/models/concerns/webhookable.rb new file mode 100644 index 00000000..5cda9df3 --- /dev/null +++ b/app/models/concerns/webhookable.rb @@ -0,0 +1,22 @@ +module Webhookable + extend ActiveSupport::Concern + + included do + after_save :omit_webhook + end + + def omit_webhook + json = { + username: user.username, + avatar_url: user.slack_avatar_url || user.github_avatar_url, + editor:, + language:, + operating_system:, + ip_address:, + user_seconds_today: user.heartbeats.today.duration_seconds, + global_seconds_today: self.class.today.group(:user_id).duration_seconds.values.sum + } + + HTTP.post("https://15a0-73-17-50-206.ngrok-free.app/heartbeat", json:) + end +end diff --git a/app/models/heartbeat.rb b/app/models/heartbeat.rb index 699349e0..74fee10f 100644 --- a/app/models/heartbeat.rb +++ b/app/models/heartbeat.rb @@ -2,6 +2,7 @@ class Heartbeat < ApplicationRecord before_save :set_fields_hash! include Heartbeatable + include Webhookable scope :today, -> { where(time: Time.current.beginning_of_day..Time.current.end_of_day) } scope :recent, -> { where("created_at > ?", 24.hours.ago) } diff --git a/config/database.yml b/config/database.yml index 45a5d8c5..11eedacf 100644 --- a/config/database.yml +++ b/config/database.yml @@ -5,30 +5,24 @@ # gem "sqlite3" # default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - timeout: 5000 development: primary: <<: *default - adapter: postgresql - encoding: unicode - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - url: <%= ENV['DATABASE_URL'] %> + database: harbour1_development wakatime: - adapter: postgresql - encoding: unicode - url: <%= ENV['WAKATIME_DATABASE_URL'] %> + database: harbour1_wt_development replica: true sailors_log: - adapter: postgresql - encoding: unicode - url: <%= ENV['SAILORS_LOG_DATABASE_URL'] %> + database: harbour1_sl_development replica: true warehouse: - adapter: postgresql - encoding: unicode - url: <%= ENV['WAREHOUSE_DATABASE_URL'] %> + database: harbour1_wh_development replica: true # Warning: The database defined as "test" will be erased and @@ -37,15 +31,11 @@ development: test: primary: <<: *default - database: test_db - username: postgres - password: postgres - # url: <%= ENV['TEST_DATABASE_URL'] %> + database: harbour1_test wakatime: - url: <%= ENV['WAKATIME_DATABASE_URL'] %> + database: harbour1_wt_test replica: true - # Store production database in the storage/ directory, which by default # is mounted as a persistent Docker volume in config/deploy.yml. production: @@ -54,7 +44,7 @@ production: adapter: postgresql encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - url: <%= ENV['DATABASE_URL'] %> + url: <%= ENV['PROD_DATABASE_URL'] %> wakatime: adapter: postgresql encoding: unicode diff --git a/config/puma.rb b/config/puma.rb index 81627d91..4d11cd78 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -28,7 +28,7 @@ threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 4000. -port ENV.fetch("PORT", 4000) +port ENV.fetch("PORT", 3000) # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart