mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 19:55:16 +00:00
Fix notification job missing class name
This commit is contained in:
parent
cfd38a87eb
commit
364b546be0
9 changed files with 98 additions and 14 deletions
31
Dockerfile.dev
Normal file
31
Dockerfile.dev
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
FROM ruby:3.4.1
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install --no-install-recommends -y \
|
||||||
|
build-essential \
|
||||||
|
git \
|
||||||
|
libpq-dev \
|
||||||
|
postgresql-client \
|
||||||
|
libvips \
|
||||||
|
pkg-config \
|
||||||
|
curl \
|
||||||
|
vim \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install application dependencies
|
||||||
|
COPY Gemfile Gemfile.lock ./
|
||||||
|
RUN bundle install
|
||||||
|
|
||||||
|
# Add a script to be executed every time the container starts
|
||||||
|
COPY entrypoint.dev.sh /usr/bin/
|
||||||
|
RUN chmod +x /usr/bin/entrypoint.dev.sh
|
||||||
|
ENTRYPOINT ["entrypoint.dev.sh"]
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the main process
|
||||||
|
CMD ["rails", "server", "-b", "0.0.0.0"]
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
class SailorsLogSlackNotificationJob < ApplicationJob
|
class SailorsLogNotifyJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform(sailors_log_slack_notification)
|
def perform(sailors_log_slack_notification_id)
|
||||||
slack_uid = sailors_log_slack_notification.slack_uid
|
slsn = SailorsLogSlackNotification.find(sailors_log_slack_notification_id)
|
||||||
slack_channel_id = sailors_log_slack_notification.slack_channel_id
|
|
||||||
project_name = sailors_log_slack_notification.project_name
|
slack_uid = slsn.slack_uid
|
||||||
project_duration = sailors_log_slack_notification.project_duration
|
slack_channel_id = slsn.slack_channel_id
|
||||||
|
project_name = slsn.project_name
|
||||||
|
project_duration = slsn.project_duration
|
||||||
|
|
||||||
kudos_message = [
|
kudos_message = [
|
||||||
"Great work!",
|
"Great work!",
|
||||||
|
|
@ -23,7 +25,7 @@ class SailorsLogSlackNotificationJob < ApplicationJob
|
||||||
|
|
||||||
message = ":boat: <@#{slack_uid}> just coded 1 more hour on #{project_name} (total: #{hours}hrs). #{kudos_message}"
|
message = ":boat: <@#{slack_uid}> just coded 1 more hour on #{project_name} (total: #{hours}hrs). #{kudos_message}"
|
||||||
|
|
||||||
response = HTTP.auth("Bearer #{ENV['SLACK_BOT_TOKEN']}")
|
response = HTTP.auth("Bearer #{ENV['SLACK_BOT_OAUTH_TOKEN']}")
|
||||||
.post("https://slack.com/api/chat.postMessage",
|
.post("https://slack.com/api/chat.postMessage",
|
||||||
json: {
|
json: {
|
||||||
channel: slack_channel_id,
|
channel: slack_channel_id,
|
||||||
|
|
@ -32,9 +34,10 @@ class SailorsLogSlackNotificationJob < ApplicationJob
|
||||||
|
|
||||||
response_data = JSON.parse(response.body)
|
response_data = JSON.parse(response.body)
|
||||||
if response_data["ok"]
|
if response_data["ok"]
|
||||||
sailors_log_slack_notification.update(sent: true)
|
slsn.update(sent: true)
|
||||||
else
|
else
|
||||||
Rails.logger.error("Failed to send Slack notification: #{response_data["error"]}")
|
Rails.logger.error("Failed to send Slack notification: #{response_data["error"]}")
|
||||||
|
throw "Failed to send Slack notification: #{response_data["error"]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -18,18 +18,17 @@ class SailorsLogPollForChangesJob < ApplicationJob
|
||||||
if new_project_time > (log.projects_summary[project] || 0) + 1.hour
|
if new_project_time > (log.projects_summary[project] || 0) + 1.hour
|
||||||
# create a new SailorsLogSlackNotification
|
# create a new SailorsLogSlackNotification
|
||||||
log.notification_preferences.each do |preference|
|
log.notification_preferences.each do |preference|
|
||||||
new_notification << {
|
log.notifications << SailorsLogSlackNotification.new(
|
||||||
slack_uid: log.slack_uid,
|
slack_uid: log.slack_uid,
|
||||||
slack_channel_id: preference.slack_channel_id,
|
slack_channel_id: preference.slack_channel_id,
|
||||||
project_name: project,
|
project_name: project,
|
||||||
project_duration: new_project_time
|
project_duration: new_project_time
|
||||||
}
|
)
|
||||||
end
|
end
|
||||||
log.projects_summary[project] = new_project_time
|
log.projects_summary[project] = new_project_time
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
SailorsLogSlackNotification.insert_all(new_notification)
|
|
||||||
log.save! if log.changed?
|
log.save! if log.changed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
class SailorsLog < ApplicationRecord
|
class SailorsLog < ApplicationRecord
|
||||||
validates :slack_uid, presence: true, uniqueness: true
|
validates :slack_uid, presence: true, uniqueness: true
|
||||||
|
validates :projects_summary, presence: true
|
||||||
|
|
||||||
after_create :initialize_projects_summary
|
after_create :initialize_projects_summary
|
||||||
|
|
||||||
has_many :notification_preferences,
|
has_many :notification_preferences,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
class SailorsLogNotificationPreference < ApplicationRecord
|
class SailorsLogNotificationPreference < ApplicationRecord
|
||||||
|
after_create :ensure_sailors_log_exists
|
||||||
|
|
||||||
belongs_to :sailors_log,
|
belongs_to :sailors_log,
|
||||||
class_name: "SailorsLog",
|
class_name: "SailorsLog",
|
||||||
foreign_key: :slack_uid,
|
foreign_key: :slack_uid,
|
||||||
primary_key: :slack_uid
|
primary_key: :slack_uid,
|
||||||
|
optional: true
|
||||||
|
private
|
||||||
|
|
||||||
|
def ensure_sailors_log_exists
|
||||||
|
SailorsLog.find_or_create_by(slack_uid: slack_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ class SailorsLogSlackNotification < ApplicationRecord
|
||||||
def notify_user
|
def notify_user
|
||||||
return if sent?
|
return if sent?
|
||||||
|
|
||||||
SailorsLogSlackNotificationJob.perform_later(self)
|
SailorsLogNotifyJob.perform_later(self.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
2
db/schema.rb
generated
2
db/schema.rb
generated
|
|
@ -142,7 +142,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_22_032930) do
|
||||||
|
|
||||||
create_table "sailors_logs", force: :cascade do |t|
|
create_table "sailors_logs", force: :cascade do |t|
|
||||||
t.string "slack_uid", null: false
|
t.string "slack_uid", null: false
|
||||||
t.jsonb "projects_summary", null: false
|
t.jsonb "projects_summary", default: {}, null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
33
docker-compose.yml
Normal file
33
docker-compose.yml
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- bundle_cache:/usr/local/bundle
|
||||||
|
environment:
|
||||||
|
- RAILS_ENV=development
|
||||||
|
- DATABASE_URL=postgres://postgres:secureorpheus123@db:5432/app_development
|
||||||
|
- POSTGRES_HOST=db
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_PASSWORD=secureorpheus123
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16
|
||||||
|
volumes:
|
||||||
|
- harbor_postgres_data:/var/lib/postgresql/data
|
||||||
|
environment:
|
||||||
|
- POSTGRES_PASSWORD=secureorpheus123
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_DB=app_development
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
harbor_postgres_data:
|
||||||
|
bundle_cache:
|
||||||
8
entrypoint.dev.sh
Normal file
8
entrypoint.dev.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Remove a potentially pre-existing server.pid for Rails
|
||||||
|
rm -f /app/tmp/pids/server.pid
|
||||||
|
|
||||||
|
# Then exec the container's main process (what's set as CMD in the Dockerfile)
|
||||||
|
exec "$@"
|
||||||
Loading…
Add table
Reference in a new issue