site_maps 0.0.1.beta1 → 0.0.1.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58b8a07d1b6a6b8774a2ee2d1dd0e3ae9ebea70095ebbf5b3c0abe4edfdece6b
4
- data.tar.gz: 472ea2dcc6760eb0f072f9ffb30b8f31fbf4fcbc25041802f44daed83c81f27c
3
+ metadata.gz: be35259a35862af6da4a12e24edba3be543aecab14266fb247e0a55e578cdc88
4
+ data.tar.gz: 9cb26be6075309e904c8958f43c7d2609e22c3c8889b205b44caef91e516b33c
5
5
  SHA512:
6
- metadata.gz: f86928a65fb91dc0f655bf45d87c3b2eedcb1fdeb08a99f509346ec9e7d8388220386322069ba6a9ecc9fb7abab667e5683ea1be42816a8dca83462251f58f27
7
- data.tar.gz: 4fafbd0e7da884694f13bf4cc6ff47db28ad8e6b04fcc0680eb671d45fbddafbec1f3d0f6420f5d6190ee439b3f9ecf74cc1307e593c8d11b97e230255788e2f
6
+ metadata.gz: daf636b9c4514158f207ca13b9b7fdfe1ac61942dfb49a9080f94460cc0c5737dddb21d5a8617ef8f211b7da104667aadd75fb03b0f6b65f9067dee2d8510eb9
7
+ data.tar.gz: f029ef9e77bd56acaaad883463ea633ede712f226f6ef335c9b06f0575d39f432b456ea9e1cde7a851765d7ad64d270fa88662f3727dc27fe2c8e821b6fb00b0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- site_maps (0.0.1.beta1)
4
+ site_maps (0.0.1.beta2)
5
5
  builder (~> 3.0)
6
6
  concurrent-ruby (>= 1.1)
7
7
  rack (>= 2.0)
@@ -111,7 +111,7 @@ GEM
111
111
  addressable (>= 2.8.0)
112
112
  crack (>= 0.3.2)
113
113
  hashdiff (>= 0.4.0, < 2.0.0)
114
- zeitwerk (2.6.18)
114
+ zeitwerk (2.7.1)
115
115
 
116
116
  PLATFORMS
117
117
  x86_64-linux
data/README.md CHANGED
@@ -148,15 +148,15 @@ bundle exec site_maps generate monthly_posts --config-file config/sitemap.rb --c
148
148
 
149
149
  You can subscribe to the internal events to receive notifications about the sitemap generation. The following events are available:
150
150
 
151
- * `sitemaps.runner.enqueue_process` - Triggered when a process is enqueued.
152
- * `sitemaps.runner.before_process_execution` - Triggered before a process starts execution
153
- * `sitemaps.runner.process_execution` - Triggered when a process finishes execution.
154
- * `sitemaps.builder.finalize_urlset` - Triggered when the sitemap builder finishes the URL set.
151
+ * `sitemaps.enqueue_process` - Triggered when a process is enqueued.
152
+ * `sitemaps.before_process_execution` - Triggered before a process starts execution
153
+ * `sitemaps.process_execution` - Triggered when a process finishes execution.
154
+ * `sitemaps.finalize_urlset` - Triggered when the sitemap builder finishes the URL set.
155
155
 
156
156
  You can subscribe to the events using the following code:
157
157
 
158
158
  ```ruby
159
- SiteMaps::Notification.subscribe("sitemaps.runner.enqueue_process") do |event|
159
+ SiteMaps::Notification.subscribe("sitemaps.enqueue_process") do |event|
160
160
  puts "Enqueueing process #{event.payload[:name]}"
161
161
  end
162
162
  ```
@@ -28,9 +28,9 @@ module SiteMaps
28
28
 
29
29
  include Publisher
30
30
 
31
- register_event "sitemaps.builder.finalize_urlset"
32
- register_event "sitemaps.runner.before_process_execution"
33
- register_event "sitemaps.runner.enqueue_process"
34
- register_event "sitemaps.runner.process_execution"
31
+ register_event "sitemaps.finalize_urlset"
32
+ register_event "sitemaps.before_process_execution"
33
+ register_event "sitemaps.enqueue_process"
34
+ register_event "sitemaps.process_execution"
35
35
  end
36
36
  end
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
4
+
3
5
  module SiteMaps
4
6
  Process = Concurrent::ImmutableStruct.new(:name, :location_template, :kwargs_template, :block) do
7
+ def id
8
+ @id ||= SecureRandom.hex(4)
9
+ end
10
+
5
11
  def location(**kwargs)
6
12
  return unless location_template
7
13
 
@@ -13,54 +13,58 @@ module SiteMaps
13
13
  method(:"on_#{method_name}")
14
14
  end
15
15
 
16
- def on_sitemaps_runner_enqueue_process(event)
16
+ def on_sitemaps_enqueue_process(event)
17
17
  process = event[:process]
18
18
  kwargs = event[:kwargs]
19
19
  location = process.location(**kwargs)
20
20
  print_message(
21
- "Enqueue process %<name>s#{" at %<location>s" if location}",
21
+ "[%<id>s] Enqueue process %<name>s#{" at %<location>s" if location}",
22
+ id: process.id,
22
23
  name: colorize(process.name, :bold),
23
24
  location: colorize(location, :lightgray)
24
25
  )
25
26
  if kwargs.any?
26
- print_message("└── Keyword Arguments: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
27
+ print_message(" └──── Context: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
27
28
  end
28
29
  end
29
30
 
30
- def on_sitemaps_runner_before_process_execution(event)
31
+ def on_sitemaps_before_process_execution(event)
31
32
  process = event[:process]
32
33
  kwargs = event[:kwargs]
33
34
  location = process.location(**kwargs)
34
35
  print_message(
35
- "Executing process %<name>s#{" at %<location>s" if location}",
36
+ "[%<id>s] Executing process %<name>s#{" at %<location>s" if location}",
37
+ id: process.id,
36
38
  name: colorize(process.name, :bold),
37
39
  location: colorize(location, :lightgray)
38
40
  )
39
41
  if kwargs.any?
40
- print_message("└── Keyword Arguments: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
42
+ print_message(" └──── Context: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
41
43
  end
42
44
  end
43
45
 
44
- def on_sitemaps_runner_process_execution(event)
46
+ def on_sitemaps_process_execution(event)
45
47
  process = event[:process]
46
48
  kwargs = event[:kwargs]
47
49
  location = process.location(**kwargs)
48
50
  print_message(
49
- "[%<runtime>s] Executed process %<name>s#{" at %<location>s" if location}",
51
+ "[%<id>s][%<runtime>s] Executed process %<name>s#{" at %<location>s" if location}",
52
+ id: process.id,
50
53
  name: colorize(process.name, :bold),
51
54
  location: colorize(location, :lightgray),
52
55
  runtime: formatted_runtime(event[:runtime])
53
56
  )
54
57
  if kwargs.any?
55
- print_message("└── Keyword Arguments: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
58
+ print_message(" └──── Context: {%<kwargs>s}", kwargs: kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", "))
56
59
  end
57
60
  end
58
61
 
59
- def on_sitemaps_builder_finalize_urlset(event)
62
+ def on_sitemaps_finalize_urlset(event)
63
+ process = event[:process]
60
64
  links_count = event[:links_count]
61
65
  news_count = event[:news_count]
62
66
  url = event[:url]
63
- text = +"[%<runtime>s] Finalize URLSet with "
67
+ text = +"[%<id>s][%<runtime>s] Finalize URLSet with "
64
68
  text << "%<links>d links" if links_count > 0
65
69
  text << " and " if links_count > 0 && news_count > 0
66
70
  text << "%<news>d news" if news_count > 0
@@ -68,6 +72,7 @@ module SiteMaps
68
72
 
69
73
  print_message(
70
74
  text,
75
+ id: process.id,
71
76
  links: links_count,
72
77
  news: news_count,
73
78
  url: colorize(url, :lightgray),
@@ -18,7 +18,7 @@ module SiteMaps
18
18
  raise ArgumentError, "Process :#{process_name} not found"
19
19
  end
20
20
  kwargs = process.keyword_arguments(kwargs)
21
- SiteMaps::Notification.instrument("sitemaps.runner.enqueue_process") do |payload|
21
+ SiteMaps::Notification.instrument("sitemaps.enqueue_process") do |payload|
22
22
  payload[:process] = process
23
23
  payload[:kwargs] = kwargs
24
24
  if process.dynamic?
@@ -53,15 +53,16 @@ module SiteMaps
53
53
  futures = []
54
54
  @execution.each do |_process_name, items|
55
55
  items.each do |process, kwargs|
56
- SiteMaps::Notification.publish("sitemaps.runner.before_process_execution", process: process, kwargs: kwargs)
56
+ SiteMaps::Notification.publish("sitemaps.before_process_execution", process: process, kwargs: kwargs)
57
57
  futures << Concurrent::Future.execute(executor: pool) do
58
58
  wrap_process_execution(process) do
59
- SiteMaps::Notification.instrument("sitemaps.runner.process_execution") do |payload|
59
+ SiteMaps::Notification.instrument("sitemaps.process_execution") do |payload|
60
60
  payload[:process] = process
61
61
  payload[:kwargs] = kwargs
62
62
  builder = SiteMaps::SitemapBuilder.new(
63
63
  adapter: adapter,
64
- location: process.location(**kwargs)
64
+ location: process.location(**kwargs),
65
+ notification_payload: { process: process }
65
66
  )
66
67
  process.call(builder, **kwargs)
67
68
  builder.finalize!
@@ -4,11 +4,12 @@ module SiteMaps
4
4
  class SitemapBuilder
5
5
  extend Forwardable
6
6
 
7
- def initialize(adapter:, location: nil)
7
+ def initialize(adapter:, location: nil, notification_payload: {})
8
8
  @adapter = adapter
9
9
  @url_set = SiteMaps::Builder::URLSet.new
10
10
  @location = location
11
11
  @mutex = Mutex.new
12
+ @notification_payload = notification_payload
12
13
  end
13
14
 
14
15
  def add(path, params: nil, **options)
@@ -31,7 +32,7 @@ module SiteMaps
31
32
 
32
33
  raw_data = url_set.finalize!
33
34
 
34
- SiteMaps::Notification.instrument("sitemaps.builder.finalize_urlset") do |payload|
35
+ SiteMaps::Notification.instrument("sitemaps.finalize_urlset", notification_payload) do |payload|
35
36
  payload[:links_count] = url_set.links_count
36
37
  payload[:news_count] = url_set.news_count
37
38
  payload[:last_modified] = url_set.last_modified
@@ -50,13 +51,13 @@ module SiteMaps
50
51
 
51
52
  protected
52
53
 
53
- attr_reader :url_set, :adapter, :location
54
+ attr_reader :url_set, :adapter, :location, :notification_payload
54
55
 
55
56
  def_delegators :adapter, :sitemap_index, :config, :repo
56
57
 
57
58
  def finalize_and_start_next_urlset!
58
59
  raw_data = url_set.finalize!
59
- SiteMaps::Notification.instrument("sitemaps.builder.finalize_urlset") do |payload|
60
+ SiteMaps::Notification.instrument("sitemaps.finalize_urlset", notification_payload) do |payload|
60
61
  sitemap_url = repo.generate_url(location)
61
62
  payload[:url] = sitemap_url
62
63
  payload[:links_count] = url_set.links_count
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SiteMaps
4
- VERSION = "0.0.1.beta1"
4
+ VERSION = "0.0.1.beta2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta1
4
+ version: 0.0.1.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos G. Zimmermann