From 611cb09556c7eb13e3190de36d6b3d9eeb09349d Mon Sep 17 00:00:00 2001 From: Malted Date: Fri, 28 Mar 2025 11:48:19 -0400 Subject: [PATCH 1/6] Remove concerns keepfile --- app/models/concerns/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/models/concerns/.keep diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29b..00000000 From abba1fafe41b35971f9960ff59fe42ee3702a236 Mon Sep 17 00:00:00 2001 From: Malted Date: Fri, 28 Mar 2025 11:48:34 -0400 Subject: [PATCH 2/6] Create webhookable concern --- app/models/concerns/webhookable.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/models/concerns/webhookable.rb diff --git a/app/models/concerns/webhookable.rb b/app/models/concerns/webhookable.rb new file mode 100644 index 00000000..d8fb418f --- /dev/null +++ b/app/models/concerns/webhookable.rb @@ -0,0 +1,15 @@ +module Webhookable + extend ActiveSupport::Concern + + included do + after_save :omit_webhook + end + + class_methods do + private + + def omit_webhook + puts "Omitting webhook!" + end + end +end From ef58aa1f940b00478b78d90038c3eca013634230 Mon Sep 17 00:00:00 2001 From: Malted Date: Fri, 28 Mar 2025 11:48:57 -0400 Subject: [PATCH 3/6] Include webhookable concern on native heartbeat --- app/models/heartbeat.rb | 1 + 1 file changed, 1 insertion(+) 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) } From fb53e3933d251317285e204ce4ade0627baf9ca1 Mon Sep 17 00:00:00 2001 From: Malted Date: Fri, 28 Mar 2025 13:13:46 -0400 Subject: [PATCH 4/6] Move `omit_webhook` outside of class_methods --- app/models/concerns/webhookable.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/webhookable.rb b/app/models/concerns/webhookable.rb index d8fb418f..f4f51488 100644 --- a/app/models/concerns/webhookable.rb +++ b/app/models/concerns/webhookable.rb @@ -5,11 +5,10 @@ module Webhookable after_save :omit_webhook end - class_methods do - private + def omit_webhook + puts "Omitting webhook!" + end - def omit_webhook - puts "Omitting webhook!" - end + class_methods do end end From 359e7de250b6ac8a7858b4a3c3414110b284050e Mon Sep 17 00:00:00 2001 From: Malted Date: Sat, 29 Mar 2025 01:34:36 -0400 Subject: [PATCH 5/6] Gather data in webhook concern --- app/models/concerns/webhookable.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/webhookable.rb b/app/models/concerns/webhookable.rb index f4f51488..dcd32f93 100644 --- a/app/models/concerns/webhookable.rb +++ b/app/models/concerns/webhookable.rb @@ -6,9 +6,17 @@ module Webhookable end def omit_webhook - puts "Omitting webhook!" - end + payload = { + 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 + }.to_json - class_methods do + return payload end end From 4da11cad7296f6fb957219598b6e6200436cafee Mon Sep 17 00:00:00 2001 From: Malted Date: Sat, 29 Mar 2025 02:41:00 -0400 Subject: [PATCH 6/6] Omit webhooks work --- app/models/concerns/webhookable.rb | 6 +++--- config/database.yml | 32 ++++++++++-------------------- config/puma.rb | 2 +- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/app/models/concerns/webhookable.rb b/app/models/concerns/webhookable.rb index dcd32f93..5cda9df3 100644 --- a/app/models/concerns/webhookable.rb +++ b/app/models/concerns/webhookable.rb @@ -6,7 +6,7 @@ module Webhookable end def omit_webhook - payload = { + json = { username: user.username, avatar_url: user.slack_avatar_url || user.github_avatar_url, editor:, @@ -15,8 +15,8 @@ def omit_webhook ip_address:, user_seconds_today: user.heartbeats.today.duration_seconds, global_seconds_today: self.class.today.group(:user_id).duration_seconds.values.sum - }.to_json + } - return payload + HTTP.post("https://15a0-73-17-50-206.ngrok-free.app/heartbeat", json:) end end 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