webhookdb 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0285d7331a0f43ff14a35e0b578d011c4d330caa9a1b9acdc04d741bbd1f35ae'
4
- data.tar.gz: 807c8366605a9de9ebd6f13502e88a892b077a1435793c5a3db6bc6b2c400dc2
3
+ metadata.gz: cd104a25c13b1c3d4a9500bdb618c2f704692c26a09a307eb926cf87bcb2befe
4
+ data.tar.gz: e61ed8994471efa0ab7ab448cf12b68cf4cbb44152df3e98024da3ffa1985c5c
5
5
  SHA512:
6
- metadata.gz: 89bf0867a274a37410d35de3ade1bef240898d518cf9377ff49acc006b56094221821e86c8ceda7ea2b2d6da68e004b58aff694c0ee778837f034f73cb0bbb22
7
- data.tar.gz: 21cc2b77bb8779ceb7e451499a90b82cd6ac211108d52441bfc203ad1334001b4a02e0d1761506d8dee6fbd56ed4fe534eb151dda96da5aa49fddfbacfaf6464
6
+ metadata.gz: 7a0839a974acd4cc643501fe544461e0848f3ee01e1e2b47bcb325dba10636556d15bb597532adb7039caa2dd4b8cf9be6fe487a4cfa211bdd82505dda1c3cc2
7
+ data.tar.gz: 4b619d15175fefaea0eafe39a57aa127c2a1b41beadf5f87fb7586e233170f30c51c02b4e20aa4701e695a42031459d9b1f11fb2ddae4ff1aa8f3d94a98aa4ee
@@ -9,7 +9,7 @@ module Webhookdb::Async::Autoscaler
9
9
  include Appydays::Configurable
10
10
  include Appydays::Loggable
11
11
 
12
- AVAILABLE_PROVIDERS = ["heroku"].freeze
12
+ AVAILABLE_PROVIDERS = ["heroku", "fake"].freeze
13
13
 
14
14
  def self._check_provider!
15
15
  return if AVAILABLE_PROVIDERS.include?(self.provider)
@@ -26,6 +26,8 @@ module Webhookdb::Async::Autoscaler
26
26
  setting :max_additional_workers, 2
27
27
  setting :latency_restored_threshold, 0
28
28
  setting :hostname_regex, /^web\.1$/, convert: ->(s) { Regexp.new(s) }
29
+ setting :heroku_app_id_or_app_name, "", key: "HEROKU_APP_NAME"
30
+ setting :heroku_formation_id_or_formation_type, "worker"
29
31
 
30
32
  after_configured do
31
33
  self._check_provider!
@@ -35,19 +37,25 @@ module Webhookdb::Async::Autoscaler
35
37
  class << self
36
38
  def enabled? = self.enabled
37
39
 
38
- def start
39
- raise "already started" unless @instance.nil?
40
+ def build_implementation
40
41
  case self.provider
41
42
  when "heroku"
42
43
  opts = {heroku: Webhookdb::Heroku.client, max_additional_workers: self.max_additional_workers}
43
44
  (opts[:app_id_or_app_name] = self.heroku_app_id_or_app_name) if
44
- self.heroku_app_id_or_app_name
45
+ self.heroku_app_id_or_app_name.present?
45
46
  (opts[:formation_id_or_formation_type] = self.heroku_formation_id_or_formation_type) if
46
- self.heroku_formation_id_or_formation_type
47
- @impl = Amigo::Autoscaler::Heroku.new(**opts)
47
+ self.heroku_formation_id_or_formation_type.present?
48
+ return Amigo::Autoscaler::Heroku.new(**opts)
49
+ when "fake"
50
+ return FakeImplementation.new
48
51
  else
49
52
  self._check_provider!
50
53
  end
54
+ end
55
+
56
+ def start
57
+ raise "already started" unless @instance.nil?
58
+ @impl = self.build_implementation
51
59
  @instance = Amigo::Autoscaler.new(
52
60
  poll_interval: self.poll_interval,
53
61
  latency_threshold: self.latency_threshold,
@@ -81,4 +89,21 @@ module Webhookdb::Async::Autoscaler
81
89
  self.logger.warn("high_latency_queues_resolved", depth:, duration:, scale_action:)
82
90
  end
83
91
  end
92
+
93
+ class FakeImplementation
94
+ attr_reader :scale_ups, :scale_downs
95
+
96
+ def initialize
97
+ @scale_ups = []
98
+ @scale_downs = []
99
+ end
100
+
101
+ def scale_up(*args)
102
+ @scale_ups << args
103
+ end
104
+
105
+ def scale_down(*args)
106
+ @scale_downs << args
107
+ end
108
+ end
84
109
  end
@@ -14,7 +14,7 @@ class Webhookdb::Heroku
14
14
  end
15
15
 
16
16
  def self.client
17
- raise "No heroku:oauth_token configured" if self.oauth_token.blank?
17
+ raise "WEBHOOKDB_HEROKU_OAUTH_TOKEN not set" if self.oauth_token.blank?
18
18
  @client ||= PlatformAPI.connect_oauth(self.oauth_token)
19
19
  return @client
20
20
  end
@@ -22,6 +22,12 @@ module Webhookdb::Tasks
22
22
  Rake::Task["specs:heroku_integration_step1"].invoke
23
23
  end
24
24
  end
25
+
26
+ desc "Print version info and exit"
27
+ task :version do
28
+ sha = Webhookdb::COMMIT[..8]
29
+ puts "#{sha} (#{Webhookdb::RELEASE}) - #{Webhookdb::RELEASE_CREATED_AT} - #{Webhookdb::RACK_ENV}"
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webhookdb
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
data/lib/webhookdb.rb CHANGED
@@ -22,6 +22,17 @@ Money.locale_backend = :i18n
22
22
  Money.default_currency = "USD"
23
23
  Money.rounding_mode = BigDecimal::ROUND_HALF_UP
24
24
 
25
+ module Appydays::Configurable
26
+ def self.fetch_env(keys, default=:__keyerror, env: ENV)
27
+ keys = [keys] unless keys.respond_to?(:to_ary)
28
+ keys.to_ary.each do |k|
29
+ return env.fetch(k) if env.key?(k)
30
+ end
31
+ raise KeyError, "no key found in env: #{keys}" if default == :__keyerror
32
+ return default
33
+ end
34
+ end
35
+
25
36
  module Webhookdb
26
37
  include Appydays::Loggable
27
38
  include Appydays::Configurable
@@ -49,10 +60,13 @@ module Webhookdb
49
60
  class RegressionModeSkip < StandardError; end
50
61
 
51
62
  APPLICATION_NAME = "Webhookdb"
52
- RACK_ENV = ENV.fetch("RACK_ENV", "development")
53
- COMMIT = ENV.fetch("HEROKU_SLUG_COMMIT", "unknown-commit")
54
- RELEASE = ENV.fetch("HEROKU_RELEASE_VERSION", "unknown-release")
55
- RELEASE_CREATED_AT = ENV.fetch("HEROKU_RELEASE_CREATED_AT") { Time.at(0).utc.iso8601 }
63
+ RACK_ENV = Appydays::Configurable.fetch_env(["RACK_ENV", "RUBY_ENV"], "development")
64
+ COMMIT = Appydays::Configurable.fetch_env(["COMMIT", "GIT_SHA", "HEROKU_SLUG_COMMIT"], "00000000")
65
+ RELEASE = Appydays::Configurable.fetch_env(["RELEASE", "GIT_REF", "HEROKU_RELEASE_VERSION"], "unknown-release")
66
+ RELEASE_CREATED_AT = Appydays::Configurable.fetch_env(
67
+ ["RELEASE_CREATED_AT", "BUILT_AT", "HEROKU_RELEASE_CREATED_AT"],
68
+ Time.at(0).utc.iso8601,
69
+ )
56
70
  INTEGRATION_TESTS_ENABLED = ENV.fetch("INTEGRATION_TESTS", false)
57
71
  require "webhookdb/version"
58
72
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhookdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WebhookDB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport