Skip to content

Create heartbeat webhook #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed app/models/concerns/.keep
Empty file.
22 changes: 22 additions & 0 deletions app/models/concerns/webhookable.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/heartbeat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
32 changes: 11 additions & 21 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading