diff --git a/ruby/hanami2-postgres/app/.gitignore b/ruby/hanami2-postgres/app/.gitignore new file mode 100644 index 00000000..ee7c0895 --- /dev/null +++ b/ruby/hanami2-postgres/app/.gitignore @@ -0,0 +1 @@ +spec/examples.txt diff --git a/ruby/hanami2-postgres/app/Gemfile b/ruby/hanami2-postgres/app/Gemfile index 345a4ba9..4e372ad1 100644 --- a/ruby/hanami2-postgres/app/Gemfile +++ b/ruby/hanami2-postgres/app/Gemfile @@ -4,10 +4,20 @@ source "https://rubygems.org" gem "appsignal", :path => "/integration" -gem "hanami", "~> 2.0.0" -gem "hanami-router", "~> 2.0.0" -gem "hanami-controller", "~> 2.0.0" -gem "hanami-validations", "~> 2.0.0" +gem "hanami", "~> 2.1.0" +gem "hanami-router", "~> 2.1.0" +gem "hanami-controller", "~> 2.1.0" +gem "hanami-validations", "~> 2.1.0" +gem "hanami-assets", "~> 2.1" +gem "hanami-view", "~> 2.1" + +group :development do + gem "hanami-webconsole", "~> 2.1" +end + +group :test do + gem "capybara" +end gem "dry-types", "~> 1.0", ">= 1.6.1" gem "puma" diff --git a/ruby/hanami2-postgres/app/Gemfile.lock b/ruby/hanami2-postgres/app/Gemfile.lock index 2d0246dc..0699662a 100644 --- a/ruby/hanami2-postgres/app/Gemfile.lock +++ b/ruby/hanami2-postgres/app/Gemfile.lock @@ -1,76 +1,52 @@ -GIT - remote: https://github.com/dry-rb/dry-types.git - revision: d926d4fb54a5ace073b3ac5324707810fa16ff86 - branch: main - specs: - dry-types (1.7.1) - concurrent-ruby (~> 1.0) - dry-core (~> 1.0) - dry-inflector (~> 1.0) - dry-logic (~> 1.4) - zeitwerk (~> 2.6) - -GIT - remote: https://github.com/rom-rb/rom.git - revision: 7fb82cf7ffa86805d9c5499a4ecc64d5d3c20f14 - branch: main - specs: - rom (6.0.0.alpha1) - concurrent-ruby (~> 1.1) - dry-core (>= 1.0.0.rc1, < 2) - dry-effects (~> 0.4) - dry-inflector (>= 1.0.0.rc1, < 2) - dry-initializer (~> 3.1) - dry-struct (~> 1.4) - dry-transformer (~> 1.0) - dry-types (~> 1.5) - zeitwerk (~> 2.6) - PATH - remote: ../../integration + remote: ../integration specs: - appsignal (3.3.6) + appsignal (4.0.0) rack -PATH - remote: /Users/luismiramirez/code/rom-sql - specs: - rom-sql (4.0.0.alpha1) - dry-core (~> 1.0) - dry-types (~> 1.7) - rom (~> 6.0.0.alpha) - sequel (>= 5) - GEM remote: https://rubygems.org/ specs: + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + better_errors (2.10.1) + erubi (>= 1.0.0) + rack (>= 0.9.0) + rouge (>= 1.0.0) + bigdecimal (3.1.8) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) coderay (1.1.3) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.3) + debug_inspector (1.2.0) diff-lcs (1.5.0) dotenv (2.8.1) dry-auto_inject (1.0.1) dry-core (~> 1.0) zeitwerk (~> 2.6) dry-cli (1.0.0) - dry-configurable (1.0.1) + dry-configurable (1.1.0) dry-core (~> 1.0, < 2) zeitwerk (~> 2.6) - dry-core (1.0.0) - concurrent-ruby (~> 1.0) - zeitwerk (~> 2.6) - dry-effects (0.4.0) + dry-core (1.0.1) concurrent-ruby (~> 1.0) - dry-core (~> 1.0) - dry-inflector (~> 1.0) - dry-initializer (~> 3.0) zeitwerk (~> 2.6) dry-events (1.0.1) concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) - dry-files (1.0.1) + dry-files (1.1.0) dry-inflector (1.0.0) dry-initializer (3.1.1) - dry-logger (1.0.3) + dry-logger (1.0.4) dry-logic (1.5.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) @@ -79,12 +55,12 @@ GEM dry-configurable (~> 1.0, < 2) dry-core (~> 1.0, < 2) dry-events (~> 1.0, < 2) - dry-schema (1.13.0) + dry-schema (1.13.4) concurrent-ruby (~> 1.0) dry-configurable (~> 1.0, >= 1.0.1) dry-core (~> 1.0, < 2) dry-initializer (~> 3.0) - dry-logic (>= 1.5, < 2) + dry-logic (>= 1.4, < 2) dry-types (>= 1.7, < 2) zeitwerk (~> 2.6) dry-struct (1.6.0) @@ -99,12 +75,20 @@ GEM dry-inflector (~> 1.0, < 2) dry-transformer (1.0.1) zeitwerk (~> 2.6) + dry-types (1.7.2) + bigdecimal (~> 3.0) + concurrent-ruby (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0) + dry-logic (~> 1.4) + zeitwerk (~> 2.6) dry-validation (1.10.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) dry-initializer (~> 3.0) dry-schema (>= 1.12, < 2) zeitwerk (~> 2.6) + erubi (1.13.0) ffi (1.15.5) formatador (1.1.0) guard (2.18.0) @@ -121,7 +105,7 @@ GEM guard (~> 2.14) guard-compat (~> 1.2) puma (>= 4.0, < 7) - hanami (2.0.3) + hanami (2.1.1) bundler (>= 1.16, < 3) dry-configurable (~> 1.0, < 2) dry-core (~> 1.0, < 2) @@ -129,26 +113,28 @@ GEM dry-logger (~> 1.0, < 2) dry-monitor (~> 1.0, >= 1.0.1, < 2) dry-system (~> 1.0, < 2) - hanami-cli (~> 2.0) - hanami-utils (~> 2.0) + hanami-cli (~> 2.1) + hanami-utils (~> 2.1) + zeitwerk (~> 2.6) + hanami-assets (2.1.0) zeitwerk (~> 2.6) - hanami-cli (2.0.3) + hanami-cli (2.1.1) bundler (~> 2.1) dry-cli (~> 1.0, < 2) - dry-files (~> 1.0, >= 1.0.1, < 2) + dry-files (~> 1.0, >= 1.0.2, < 2) dry-inflector (~> 1.0, < 2) rake (~> 13.0) zeitwerk (~> 2.6) - hanami-controller (2.0.2) + hanami-controller (2.1.0) dry-configurable (~> 1.0, < 2) dry-core (~> 1.0) - hanami-utils (~> 2.0) + hanami-utils (~> 2.1) rack (~> 2.0) zeitwerk (~> 2.6) hanami-reloader (2.0.2) hanami-cli (~> 2.0) zeitwerk (~> 2.6) - hanami-router (2.0.2) + hanami-router (2.1.0) mustermann (~> 3.0) mustermann-contrib (~> 3.0) rack (~> 2.0) @@ -157,20 +143,32 @@ GEM rake (~> 13.0) rspec (~> 3.12) zeitwerk (~> 2.6) - hanami-utils (2.0.3) + hanami-utils (2.1.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) dry-transformer (~> 1.0, < 2) - hanami-validations (2.0.1) + hanami-validations (2.1.0) dry-validation (>= 1.10, < 2) zeitwerk (~> 2.6.0) + hanami-view (2.1.0) + dry-configurable (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0, < 2) + temple (~> 0.10.0, >= 0.10.2) + tilt (~> 2.3) + zeitwerk (~> 2.6) + hanami-webconsole (2.1.0) + better_errors (~> 2.10, >= 2.10.1) + binding_of_caller (~> 1.0) hansi (0.2.1) ice_nine (0.11.2) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) lumberjack (1.2.8) + matrix (0.4.2) method_source (1.0.0) + mini_mime (1.1.5) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mustermann-contrib (3.0.0) @@ -178,6 +176,10 @@ GEM mustermann (= 3.0.0) nenv (0.3.0) nio4r (2.5.8) + nokogiri (1.16.6-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.6-arm64-darwin) + racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) @@ -185,15 +187,45 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) + public_suffix (6.0.0) puma (6.1.1) nio4r (~> 2.0) - rack (2.2.6.3) + racc (1.8.0) + rack (2.2.9) rack-test (2.0.2) rack (>= 1.3) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) + regexp_parser (2.9.2) + rom (5.3.2) + rom-changeset (~> 5.3, >= 5.3.0) + rom-core (~> 5.3, >= 5.3.2) + rom-repository (~> 5.3, >= 5.3.0) + rom-changeset (5.3.0) + dry-core (~> 1.0) + rom-core (~> 5.3) + transproc (~> 1.0, >= 1.1.0) + rom-core (5.3.2) + concurrent-ruby (~> 1.1) + dry-configurable (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0) + dry-initializer (~> 3.0, >= 3.0.1) + dry-struct (~> 1.0) + dry-types (~> 1.6) + transproc (~> 1.0, >= 1.1.0) + rom-repository (5.3.0) + dry-core (~> 1.0) + dry-initializer (~> 3.0, >= 3.0.1) + rom-core (~> 5.3, >= 5.3.0) + rom-sql (3.6.3) + dry-core (~> 1.0) + dry-types (~> 1.0) + rom (~> 5.2, >= 5.2.1) + sequel (>= 4.49) + rouge (4.3.0) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -208,10 +240,16 @@ GEM rspec-support (~> 3.12.0) rspec-support (3.12.0) ruby2_keywords (0.0.5) - sequel (5.66.0) + sequel (5.81.0) + bigdecimal shellany (0.0.1) + temple (0.10.3) thor (1.2.1) - zeitwerk (2.6.7) + tilt (2.3.0) + transproc (1.1.1) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.16) PLATFORMS aarch64-linux @@ -219,21 +257,25 @@ PLATFORMS DEPENDENCIES appsignal! + capybara dotenv - dry-types! + dry-types (~> 1.0, >= 1.6.1) guard-puma - hanami (~> 2.0.0) - hanami-controller (~> 2.0.0) + hanami (~> 2.1.0) + hanami-assets (~> 2.1) + hanami-controller (~> 2.1.0) hanami-reloader - hanami-router (~> 2.0.0) + hanami-router (~> 2.1.0) hanami-rspec - hanami-validations (~> 2.0.0) + hanami-validations (~> 2.1.0) + hanami-view (~> 2.1) + hanami-webconsole (~> 2.1) pg puma rack-test rake - rom! - rom-sql! + rom (~> 5.3) + rom-sql (~> 3.6) BUNDLED WITH 2.3.26 diff --git a/ruby/hanami2-postgres/app/Guardfile b/ruby/hanami2-postgres/app/Guardfile index 7840c084..196d8118 100644 --- a/ruby/hanami2-postgres/app/Guardfile +++ b/ruby/hanami2-postgres/app/Guardfile @@ -1,10 +1,9 @@ # frozen_string_literal: true group :server do - guard "puma", port: ENV["HANAMI_PORT"] || 2300 do - watch(%r{config/*}) - watch(%r{lib/*}) - watch(%r{app/*}) - watch(%r{slices/*}) + guard "puma", port: ENV.fetch("HANAMI_PORT", 2300) do + # Edit the following regular expression for your needs. + # See: https://guides.hanamirb.org/app/code-reloading/ + watch(%r{^(app|config|lib|slices)([\/][^\/]+)*.(rb|erb|haml|slim)$}i) end end diff --git a/ruby/hanami2-postgres/app/Procfile b/ruby/hanami2-postgres/app/Procfile new file mode 100644 index 00000000..d8377a41 --- /dev/null +++ b/ruby/hanami2-postgres/app/Procfile @@ -0,0 +1,2 @@ +web: bundle exec hanami server +assets: bundle exec hanami assets watch diff --git a/ruby/hanami2-postgres/app/app/action.rb b/ruby/hanami2-postgres/app/app/action.rb index 66f0cb66..66ba3ef0 100644 --- a/ruby/hanami2-postgres/app/app/action.rb +++ b/ruby/hanami2-postgres/app/app/action.rb @@ -11,7 +11,7 @@ class Action < Hanami::Action def handle_standard_error(request, response, exception) # Report the error to AppSignal - Appsignal.set_error(exception) + Appsignal.report_error(exception) # Render custom error page response.status = 500 diff --git a/ruby/hanami2-postgres/app/bin/dev b/ruby/hanami2-postgres/app/bin/dev new file mode 100755 index 00000000..74ade166 --- /dev/null +++ b/ruby/hanami2-postgres/app/bin/dev @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +if ! gem list foreman -i --silent; then + echo "Installing foreman..." + gem install foreman +fi + +exec foreman start -f Procfile.dev "$@" diff --git a/ruby/hanami2-postgres/app/config.ru b/ruby/hanami2-postgres/app/config.ru index 5f771307..106273eb 100644 --- a/ruby/hanami2-postgres/app/config.ru +++ b/ruby/hanami2-postgres/app/config.ru @@ -1,8 +1,9 @@ # frozen_string_literal: true +require "appsignal" require "hanami/boot" -require "appsignal/integrations/hanami" -pp Hanami.app.config +Appsignal.load(:hanami) +Appsignal.start run Hanami.app diff --git a/ruby/hanami2-postgres/app/config/puma.rb b/ruby/hanami2-postgres/app/config/puma.rb index 814785f0..2d82081e 100644 --- a/ruby/hanami2-postgres/app/config/puma.rb +++ b/ruby/hanami2-postgres/app/config/puma.rb @@ -1,15 +1,49 @@ # frozen_string_literal: true +plugin :appsignal + +# +# Environment and port +# +port ENV.fetch("HANAMI_PORT", 2300) +environment ENV.fetch("HANAMI_ENV", "development") + +# +# Threads within each Puma/Ruby process (aka worker) +# + +# Configure the minimum and maximum number of threads to use to answer requests. max_threads_count = ENV.fetch("HANAMI_MAX_THREADS", 5) min_threads_count = ENV.fetch("HANAMI_MIN_THREADS") { max_threads_count } + threads min_threads_count, max_threads_count -port ENV.fetch("HANAMI_PORT", 2300) -environment ENV.fetch("HANAMI_ENV", "development") -workers ENV.fetch("HANAMI_WEB_CONCURRENCY", 2) +# +# Workers (aka Puma/Ruby processes) +# -on_worker_boot do - Hanami.shutdown -end +puma_concurrency = Integer(ENV.fetch("HANAMI_WEB_CONCURRENCY", 0)) +puma_cluster_mode = puma_concurrency > 1 + +# How many worker (Puma/Ruby) processes to run. +# Typically this is set to the number of available cores. +workers puma_concurrency + +# +# Cluster mode (aka multiple workers) +# -preload_app! +if puma_cluster_mode + # Preload the application before starting the workers. Only in cluster mode. + preload_app! + + # Code to run immediately before master process forks workers (once on boot). + # + # These hooks can block if necessary to wait for background operations unknown + # to puma to finish before the process terminates. This can be used to close + # any connections to remote servers (database, redis, …) that were opened when + # preloading the code. + before_fork do + Hanami.shutdown + end +end diff --git a/ruby/hanami2-postgres/app/spec/spec_helper.rb b/ruby/hanami2-postgres/app/spec/spec_helper.rb index b0ce0923..ca3a4dea 100644 --- a/ruby/hanami2-postgres/app/spec/spec_helper.rb +++ b/ruby/hanami2-postgres/app/spec/spec_helper.rb @@ -7,4 +7,5 @@ require "hanami/prepare" require_relative "support/rspec" +require_relative "support/features" require_relative "support/requests" diff --git a/ruby/hanami2-postgres/app/spec/support/features.rb b/ruby/hanami2-postgres/app/spec/support/features.rb new file mode 100644 index 00000000..2de8e796 --- /dev/null +++ b/ruby/hanami2-postgres/app/spec/support/features.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require "capybara/rspec" + +Capybara.app = Hanami.app diff --git a/ruby/hanami2-postgres/app/spec/support/rspec.rb b/ruby/hanami2-postgres/app/spec/support/rspec.rb index 96349835..d48d3bb5 100644 --- a/ruby/hanami2-postgres/app/spec/support/rspec.rb +++ b/ruby/hanami2-postgres/app/spec/support/rspec.rb @@ -22,6 +22,8 @@ config.profile_examples = 10 + config.example_status_persistence_file_path = "spec/examples.txt" + config.order = :random Kernel.srand config.seed end