pechkin 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pechkin/app/app.rb +8 -2
- data/lib/pechkin/app/request_handler.rb +3 -2
- data/lib/pechkin/cli.rb +9 -0
- data/lib/pechkin/command/run_server.rb +13 -4
- data/lib/pechkin/command/send_data.rb +1 -1
- data/lib/pechkin/configuration/configuration_loader_views.rb +1 -1
- data/lib/pechkin/message_template.rb +1 -2
- data/lib/pechkin/version.rb +1 -1
- data/lib/pechkin.rb +1 -0
- metadata +27 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41f0579677371d43215ee3c53c0e9eb1b4e02206bdbf1b1bc1d4898cbd58c981
|
4
|
+
data.tar.gz: 127385b4694d80fdbbe733bc646ee3b5922db83119912afb6e50f6de84b29e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 670ffbaf73bbfefbe54ca3f0a1d06d863c3548f41e35c2580e48644f0967009af8818f20fcc5d0256bd59509817a581e322a5140f870e47c62cf30572e3796aa
|
7
|
+
data.tar.gz: 5059e3fd4354f996692013a819e879a61ccf943737c2d7ed824beb8b5095ce940c5b3b700a10e53044694924e277614db3816bb9370a3098c00b8d867bb823fc
|
data/lib/pechkin/app/app.rb
CHANGED
@@ -2,7 +2,7 @@ module Pechkin
|
|
2
2
|
# Rack application to handle requests
|
3
3
|
class App
|
4
4
|
DEFAULT_CONTENT_TYPE = { 'Content-Type' => 'application/json' }.freeze
|
5
|
-
DEFAULT_HEADERS = {}.merge(DEFAULT_CONTENT_TYPE)
|
5
|
+
DEFAULT_HEADERS = {}.merge(DEFAULT_CONTENT_TYPE)
|
6
6
|
|
7
7
|
attr_accessor :handler, :logger
|
8
8
|
|
@@ -12,6 +12,12 @@ module Pechkin
|
|
12
12
|
|
13
13
|
def call(env)
|
14
14
|
req = Rack::Request.new(env)
|
15
|
+
|
16
|
+
# Stub for favicon.ico
|
17
|
+
if req.path_info == '/favicon.ico'
|
18
|
+
return response(405, '') # Return empty response 405 Method Not Allowed
|
19
|
+
end
|
20
|
+
|
15
21
|
result = RequestHandler.new(handler, req, logger).handle
|
16
22
|
response(200, result)
|
17
23
|
rescue AppError => e
|
@@ -23,7 +29,7 @@ module Pechkin
|
|
23
29
|
private
|
24
30
|
|
25
31
|
def response(code, body)
|
26
|
-
[code.to_s, DEFAULT_HEADERS, [body.to_json]]
|
32
|
+
[code.to_s, DEFAULT_HEADERS.dup, [body.to_json]]
|
27
33
|
end
|
28
34
|
|
29
35
|
def proces_app_error(req, err)
|
@@ -2,7 +2,7 @@ module Pechkin
|
|
2
2
|
# Http requests handler. We need fresh instance per each request. To keep
|
3
3
|
# internal state isolated
|
4
4
|
class RequestHandler
|
5
|
-
REQ_PATH_PATTERN = %r{^/(.+)/([^/]+)/?$}
|
5
|
+
REQ_PATH_PATTERN = %r{^/(.+)/([^/]+)/?$}
|
6
6
|
|
7
7
|
attr_reader :req, :handler,
|
8
8
|
:channel_id, :message_id,
|
@@ -23,7 +23,8 @@ module Pechkin
|
|
23
23
|
raise AppError.message_not_found unless message?
|
24
24
|
|
25
25
|
data = parse_data(req.body.read)
|
26
|
-
handler.handle(
|
26
|
+
# handler.handle() requires keyword arguments
|
27
|
+
handler.handle(channel_id, message_id, **data).each do |i|
|
27
28
|
logger.info "Sent #{channel_id}/#{message_id}: #{i.to_json}"
|
28
29
|
end
|
29
30
|
end
|
data/lib/pechkin/cli.rb
CHANGED
@@ -102,6 +102,15 @@ module Pechkin
|
|
102
102
|
opt :pid_file, names: ['-p', '--pid-file [FILE]'],
|
103
103
|
desc: 'Path to output PID file'
|
104
104
|
|
105
|
+
opt :server_workers, names: ['--min-threads [SERVER_WORKERS]'], default: 2, type: Integer,
|
106
|
+
desc: 'Server workers count. Default: 1'
|
107
|
+
|
108
|
+
opt :min_threads, names: ['--min-threads [MIN_THREADS]'], default: 5, type: Integer,
|
109
|
+
desc: 'Min threads count. Default: 5'
|
110
|
+
|
111
|
+
opt :max_threads, names: ['--max-threads [MAX_THREADS]'], default: 20, type: Integer,
|
112
|
+
desc: 'Max threads count. Default: 20'
|
113
|
+
|
105
114
|
opt :log_dir, names: ['--log-dir [DIR]'],
|
106
115
|
desc: 'Path to log directory. Output will be writen to' \
|
107
116
|
'pechkin.log file. If not specified will write to ' \
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'puma/configuration'
|
2
|
+
|
1
3
|
module Pechkin
|
2
4
|
module Command
|
3
5
|
# Start pechkin HTTP server
|
@@ -7,10 +9,17 @@ module Pechkin
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def execute
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
# Configure Puma server instead config.ru
|
13
|
+
puma_config = Puma::Configuration.new do |user_config|
|
14
|
+
user_config.bind "tcp://#{options.bind_address}:#{options.port}"
|
15
|
+
user_config.workers options.server_workers # Set number of workers
|
16
|
+
user_config.threads options.min_threads, options.max_threads # Set max and min threads
|
17
|
+
user_config.app AppBuilder.new.build(handler, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Run Puma server with configuration
|
21
|
+
launcher = Puma::Launcher.new(puma_config)
|
22
|
+
launcher.run
|
14
23
|
end
|
15
24
|
end
|
16
25
|
end
|
@@ -18,7 +18,7 @@ module Pechkin
|
|
18
18
|
raise ConfigurationError, "'#{views_dir}' is not a directory" unless File.directory?(views_dir)
|
19
19
|
|
20
20
|
Dir["#{views_dir}/**/*.erb"].each do |f|
|
21
|
-
relative_path = f["#{views_dir}/".length
|
21
|
+
relative_path = f["#{views_dir}/".length..]
|
22
22
|
views[relative_path] = MessageTemplate.new(IO.read(f))
|
23
23
|
end
|
24
24
|
end
|
@@ -18,9 +18,8 @@ module Pechkin
|
|
18
18
|
if MessageTemplate::ERB_INITIALIZE_KEYWORD_ARGUMENTS # Ruby 2.6+
|
19
19
|
@erb_template = ERB.new(erb, trim_mode: '-')
|
20
20
|
else
|
21
|
-
safe_level = nil
|
22
21
|
trim_mode = '-'
|
23
|
-
@erb_template = ERB.new(erb,
|
22
|
+
@erb_template = ERB.new(erb, trim_mode: trim_mode)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
data/lib/pechkin/version.rb
CHANGED
data/lib/pechkin.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pechkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Arkhanhelsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htauth
|
@@ -16,56 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: powerpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.
|
40
|
+
version: 0.1.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: prometheus-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.2.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.2.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: puma
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.4.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.4.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rack
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - '='
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 3.0.8
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - '='
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 3.0.8
|
69
83
|
description:
|
70
84
|
email: ilya.arkhanhelsky at gmail.com
|
71
85
|
executables:
|
@@ -118,16 +132,16 @@ require_paths:
|
|
118
132
|
- lib
|
119
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
134
|
requirements:
|
121
|
-
- - "
|
135
|
+
- - ">="
|
122
136
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
137
|
+
version: '3.0'
|
124
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
139
|
requirements:
|
126
140
|
- - ">="
|
127
141
|
- !ruby/object:Gem::Version
|
128
142
|
version: '0'
|
129
143
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.4.10
|
131
145
|
signing_key:
|
132
146
|
specification_version: 4
|
133
147
|
summary: Web service to proxy webhooks to Telegram Bot API
|