diff --git a/app/relations/auto_taggings.rb b/app/relations/auto_taggings.rb new file mode 100644 index 0000000..9234047 --- /dev/null +++ b/app/relations/auto_taggings.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class AutoTaggings < ROM::Relation[:sql] + schema :auto_taggings, infer: true do + associations do + belongs_to :tag + end + end + + auto_struct(true) + end + end +end diff --git a/app/relations/movies.rb b/app/relations/movies.rb new file mode 100644 index 0000000..5a443b3 --- /dev/null +++ b/app/relations/movies.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Movies < ROM::Relation[:sql] + schema :movies, infer: true + + auto_struct(true) + end + end +end diff --git a/app/relations/podcasts.rb b/app/relations/podcasts.rb new file mode 100644 index 0000000..ba96774 --- /dev/null +++ b/app/relations/podcasts.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Podcasts < ROM::Relation[:sql] + schema :podcasts, infer: true + + auto_struct(true) + end + end +end diff --git a/app/relations/post_tags.rb b/app/relations/post_tags.rb new file mode 100644 index 0000000..23a1bb2 --- /dev/null +++ b/app/relations/post_tags.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class PostTags < ROM::Relation[:sql] + schema :post_tags, infer: true do + associations do + belongs_to :post + belongs_to :tag + end + end + + auto_struct(true) + end + end +end diff --git a/app/relations/post_trips.rb b/app/relations/post_trips.rb new file mode 100644 index 0000000..85cb19a --- /dev/null +++ b/app/relations/post_trips.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class PostTrips < ROM::Relation[:sql] + schema :post_trips, infer: true do + associations do + belongs_to :post + belongs_to :trip + end + end + + auto_struct(true) + end + end +end diff --git a/app/relations/posts.rb b/app/relations/posts.rb new file mode 100644 index 0000000..a615244 --- /dev/null +++ b/app/relations/posts.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Posts < ROM::Relation[:sql] + schema :posts, infer: true do + associations do + has_many :post_tags + has_many :tags, through: :post_tags + + has_many :post_trips + has_many :trips, through: :post_trips + + has_many :webmentions + end + end + + auto_struct(true) + + def published + where(self[:published_at] <= Time.now) + end + + def weekly + ref = post_tags.where(tag_id: "70").select(:post_id).dataset + where(id: ref) + end + + def non_weekly + ref = post_tags.where(tag_id: "70").select(:post_id).dataset + exclude(id: ref) + end + + def published_between(start_date, end_date) + where(self[:published_at] >= start_date) + .where(self[:published_at] <= end_date) + end + end + end +end diff --git a/app/relations/tags.rb b/app/relations/tags.rb new file mode 100644 index 0000000..367f05d --- /dev/null +++ b/app/relations/tags.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Tags < ROM::Relation[:sql] + schema :tags, infer: true do + associations do + has_many :post_tags + has_many :posts, through: :post_tags + end + end + + auto_struct(true) + end + end +end diff --git a/app/relations/top_tracks.rb b/app/relations/top_tracks.rb new file mode 100644 index 0000000..ce09983 --- /dev/null +++ b/app/relations/top_tracks.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class TopTracks < ROM::Relation[:sql] + schema :top_tracks, infer: true + + auto_struct(true) + end + end +end diff --git a/app/relations/trips.rb b/app/relations/trips.rb new file mode 100644 index 0000000..f400e6b --- /dev/null +++ b/app/relations/trips.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Trips < ROM::Relation[:sql] + schema :trips, infer: true do + associations do + has_many :post_trips + has_many :posts, through: :post_trips + end + end + + auto_struct(true) + + def published + where(self[:start_date] <= Time.now) + end + end + end +end diff --git a/app/relations/webmentions.rb b/app/relations/webmentions.rb new file mode 100644 index 0000000..6a691b6 --- /dev/null +++ b/app/relations/webmentions.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Webmentions < ROM::Relation[:sql] + schema :webmentions, infer: true do + associations do + belongs_to :post + end + end + + auto_struct(true) + + def published + where(self[:published_at] <= Time.now) + end + end + end +end diff --git a/app/relations/workouts.rb b/app/relations/workouts.rb new file mode 100644 index 0000000..0f39d4d --- /dev/null +++ b/app/relations/workouts.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Adamantium + module Relations + class Workouts < ROM::Relation[:sql] + schema :workouts, infer: true + + auto_struct(true) + end + end +end diff --git a/config/providers/persistence.rb b/config/providers/persistence.rb index 0ffd8c7..0e03cf0 100644 --- a/config/providers/persistence.rb +++ b/config/providers/persistence.rb @@ -24,13 +24,17 @@ Hanami.app.register_provider :persistence, namespace: true do start do rom_config = target["persistence.config"] rom_config.auto_registration( - target.root.join("lib/adamantium/persistence"), - namespace: "Adamantium::Persistence" + target.root.join("app"), + namespace: Hanami.app.namespace.to_s ) register "rom", ROM.container(rom_config) end + stop do + target["persistence.rom"].disconnect + end + define_method(:silence_warnings) do |&block| orig_verbose = $VERBOSE $VERBOSE = nil diff --git a/config/puma.rb b/config/puma.rb index e33d5bd..0a96f8c 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,17 +1,47 @@ # frozen_string_literal: true -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 - +# +# Environment and port +# port ENV.fetch("HANAMI_PORT", 2300) environment ENV.fetch("HANAMI_ENV", "development") -workers ENV.fetch("HANAMI_WEB_CONCURRENCY", 2) -on_worker_boot do - Hanami.shutdown -end +# +# Threads within each Puma/Ruby process (aka worker) +# -pidfile ENV.fetch("PIDFILE", "tmp/pids/puma.pid") +# 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 } -preload_app! +threads min_threads_count, max_threads_count + +# +# Workers (aka Puma/Ruby processes) +# + +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) +# + +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 \ No newline at end of file diff --git a/lib/adamantium/persistence/relations/auto_taggings.rb b/lib/adamantium/persistence/relations/auto_taggings.rb deleted file mode 100644 index bb1e8a2..0000000 --- a/lib/adamantium/persistence/relations/auto_taggings.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class AutoTaggings < ROM::Relation[:sql] - schema :auto_taggings, infer: true do - associations do - belongs_to :tag - end - end - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/movies.rb b/lib/adamantium/persistence/relations/movies.rb deleted file mode 100644 index 1ea0580..0000000 --- a/lib/adamantium/persistence/relations/movies.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Movies < ROM::Relation[:sql] - schema :movies, infer: true - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/podcasts.rb b/lib/adamantium/persistence/relations/podcasts.rb deleted file mode 100644 index a4cb82c..0000000 --- a/lib/adamantium/persistence/relations/podcasts.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Podcasts < ROM::Relation[:sql] - schema :podcasts, infer: true - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/post_tags.rb b/lib/adamantium/persistence/relations/post_tags.rb deleted file mode 100644 index 30d7736..0000000 --- a/lib/adamantium/persistence/relations/post_tags.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class PostTags < ROM::Relation[:sql] - schema :post_tags, infer: true do - associations do - belongs_to :post - belongs_to :tag - end - end - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/post_trips.rb b/lib/adamantium/persistence/relations/post_trips.rb deleted file mode 100644 index 6372cda..0000000 --- a/lib/adamantium/persistence/relations/post_trips.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class PostTrips < ROM::Relation[:sql] - schema :post_trips, infer: true do - associations do - belongs_to :post - belongs_to :trip - end - end - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/posts.rb b/lib/adamantium/persistence/relations/posts.rb deleted file mode 100644 index 9ee2cf7..0000000 --- a/lib/adamantium/persistence/relations/posts.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Posts < ROM::Relation[:sql] - schema :posts, infer: true do - associations do - has_many :post_tags - has_many :tags, through: :post_tags - - has_many :post_trips - has_many :trips, through: :post_trips - - has_many :webmentions - end - end - - auto_struct(true) - - def published - where(self[:published_at] <= Time.now) - end - - def weekly - ref = post_tags.where(tag_id: "70").select(:post_id).dataset - where(id: ref) - end - - def non_weekly - ref = post_tags.where(tag_id: "70").select(:post_id).dataset - exclude(id: ref) - end - - def published_between(start_date, end_date) - where(self[:published_at] >= start_date) - .where(self[:published_at] <= end_date) - end - end - end - end -end diff --git a/lib/adamantium/persistence/relations/tags.rb b/lib/adamantium/persistence/relations/tags.rb deleted file mode 100644 index d3bcb05..0000000 --- a/lib/adamantium/persistence/relations/tags.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Tags < ROM::Relation[:sql] - schema :tags, infer: true do - associations do - has_many :post_tags - has_many :posts, through: :post_tags - end - end - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/top_tracks.rb b/lib/adamantium/persistence/relations/top_tracks.rb deleted file mode 100644 index 7ad9a73..0000000 --- a/lib/adamantium/persistence/relations/top_tracks.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class TopTracks < ROM::Relation[:sql] - schema :top_tracks, infer: true - - auto_struct(true) - end - end - end -end diff --git a/lib/adamantium/persistence/relations/trips.rb b/lib/adamantium/persistence/relations/trips.rb deleted file mode 100644 index 17a31ee..0000000 --- a/lib/adamantium/persistence/relations/trips.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Trips < ROM::Relation[:sql] - schema :trips, infer: true do - associations do - has_many :post_trips - has_many :posts, through: :post_trips - end - end - - auto_struct(true) - - def published - where(self[:start_date] <= Time.now) - end - end - end - end -end diff --git a/lib/adamantium/persistence/relations/webmentions.rb b/lib/adamantium/persistence/relations/webmentions.rb deleted file mode 100644 index 049cac0..0000000 --- a/lib/adamantium/persistence/relations/webmentions.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Webmentions < ROM::Relation[:sql] - schema :webmentions, infer: true do - associations do - belongs_to :post - end - end - - auto_struct(true) - - def published - where(self[:published_at] <= Time.now) - end - end - end - end -end diff --git a/lib/adamantium/persistence/relations/workouts.rb b/lib/adamantium/persistence/relations/workouts.rb deleted file mode 100644 index 9cd5db1..0000000 --- a/lib/adamantium/persistence/relations/workouts.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Adamantium - module Persistence - module Relations - class Workouts < ROM::Relation[:sql] - schema :workouts, infer: true - - auto_struct(true) - end - end - end -end