Add connection to wakatime db

This commit is contained in:
Max Wofford
2025-02-16 12:28:11 -05:00
parent 5f6b322ebe
commit ef9b1c7d0b
6 changed files with 40 additions and 39 deletions

View File

@@ -6,6 +6,8 @@ gem "rails", "~> 8.0.1"
gem "propshaft"
# Use sqlite3 as the database for Active Record
gem "sqlite3", ">= 2.1"
# Use PostgreSQL as the database for Wakatime
gem "pg"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]

View File

@@ -111,12 +111,6 @@ GEM
erubi (1.13.1)
et-orbi (1.2.11)
tzinfo
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-arm-linux-gnu)
@@ -132,7 +126,6 @@ GEM
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
hashie (5.0.0)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
@@ -157,8 +150,6 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.10.1)
jwt (2.10.1)
base64
kamal (2.5.2)
activesupport (>= 7.0)
base64 (~> 0.2)
@@ -189,11 +180,6 @@ GEM
mini_mime (1.1.5)
minitest (5.25.4)
msgpack (1.8.0)
multi_json (1.15.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-http (0.6.0)
uri
net-imap (0.5.6)
date
net-protocol
@@ -223,28 +209,12 @@ GEM
racc (~> 1.4)
nokogiri (1.18.2-x86_64-linux-musl)
racc (~> 1.4)
oauth2 (1.4.11)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
omniauth (1.9.2)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
omniauth-oauth2 (1.3.1)
oauth2 (~> 1.0)
omniauth (~> 1.2)
omniauth-rails_csrf_protection (0.1.2)
actionpack (>= 4.2)
omniauth (>= 1.3.1)
omniauth-slack (2.3.0)
omniauth-oauth2 (~> 1.3.1)
ostruct (0.6.1)
parallel (1.26.3)
parser (3.3.7.1)
ast (~> 2.4.1)
racc
pg (1.5.9)
pp (0.6.2)
prettyprint
prettyprint (0.2.0)
@@ -432,9 +402,7 @@ DEPENDENCIES
importmap-rails
jbuilder
kamal
omniauth
omniauth-rails_csrf_protection
omniauth-slack
pg
propshaft
puma (>= 5.0)
rails (~> 8.0.1)

9
app/models/heartbeat.rb Normal file
View File

@@ -0,0 +1,9 @@
class Heartbeat < WakatimeRecord
def self.cached_recent_count
Rails.cache.fetch("heartbeats_recent_count", expires_in: 5.minutes) do
recent.count
end
end
scope :recent, -> { where("created_at > ?", 24.hours.ago) }
end

View File

@@ -0,0 +1,4 @@
class WakatimeRecord < ApplicationRecord
self.abstract_class = true
connects_to database: { reading: :wakatime, writing: :wakatime }
end

View File

@@ -38,7 +38,8 @@
<%= yield %>
<footer style="position: fixed; bottom: 0; width: 100%; padding: 10px; background-color: #f5f5f5; text-align: center; font-size: 12px;">
Build <%= Rails.application.config.git_version %> from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago
Build <%= Rails.application.config.git_version %> from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago.
<%= Heartbeat.cached_recent_count %> heartbeats in the last 24 hours.
</footer>
</body>
</html>

View File

@@ -10,15 +10,27 @@ default: &default
timeout: 5000
development:
<<: *default
database: storage/development.sqlite3
primary:
<<: *default
database: storage/development.sqlite3
wakatime:
adapter: postgresql
encoding: unicode
url: <%= ENV['WAKATIME_DATABASE_URL'] %>
replica: true
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: storage/test.sqlite3
primary:
<<: *default
database: storage/test.sqlite3
wakatime:
adapter: postgresql
encoding: unicode
url: <%= ENV['WAKATIME_DATABASE_URL'] %>
replica: true
# Store production database in the storage/ directory, which by default
@@ -27,6 +39,11 @@ production:
primary:
<<: *default
database: storage/production.sqlite3
wakatime:
adapter: postgresql
encoding: unicode
url: <%= ENV['WAKATIME_DATABASE_URL'] %>
replica: true
cache:
<<: *default
database: storage/production_cache.sqlite3