macaw_framework 1.1.2 → 1.1.3

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: 684896888c97d23fc4763ddbf106a7248ca22acedb7550371cdc912a34e4e9ef
4
- data.tar.gz: 8188e16ee9193d334360de46c66e7fadbb054e1ffd10183d8967cbc2fb1b763f
3
+ metadata.gz: 206cdc56fc4e1027b3f1cc5d98b57a531c4043500cb1e99545b6e198c9b01f9d
4
+ data.tar.gz: 954b2f0bcbfea9bdc8e0a39362455e3c155e7b04f7b2accf786c6be658740c65
5
5
  SHA512:
6
- metadata.gz: b3de5c64a50e8cb95eff2d9d13cbae3a5d24d60f42c4be2ccea7459bf28aaa0ed80d2aaa2a47a64e69fb4eacc8d354d78b38505c9e31b176481ba96aca3b4af7
7
- data.tar.gz: 148d541c0ba4d2c6790e939da810e02dd405dd8bc056e8af38ef90bb8f7832b9a366933b3d5fce14df03bc9516d52b41f6a4294f47d8133d2dba1740b32ae0d9
6
+ metadata.gz: ec8a983e02579327ef6987a86267094ed0d0384ed8f1da4c244b0c77d27b1ddae2de4e1ef94020ab90824055ae892f03f5884ce724ec596551622e25ee88d167
7
+ data.tar.gz: 9a90daa6f5884b4148728b89780a6fb118e071e932c6e437c4efa8f4f548b7624d021bb540e25f929d584c20e398974c27e962869e0d7337894466e0cf914a37
data/CHANGELOG.md CHANGED
@@ -85,3 +85,9 @@
85
85
  - Fixing retry bug in cron jobs, where retries were made after an exception without waiting for interval
86
86
  - Fixing another bug in cron jobs where an exception were thrown when start_delay were not set
87
87
  - Documentation improvement
88
+
89
+ ## [1.1.3] - 2023-05-31
90
+
91
+ - Adding start_without_server! method for starting the framework without running a web server
92
+ - Improving documentation
93
+ - Raising the number of default threads from 5 to 10
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/macaw_framework.svg)](https://badge.fury.io/rb/macaw_framework) ![CI Pipeline](https://github.com/ariasdiniz/macaw_framework/actions/workflows/main.yml/badge.svg?branch=main)
1
2
  # MacawFramework
2
3
 
3
4
  MacawFramework is a lightweight, easy-to-use web framework for Ruby designed to simplify the development of small to
@@ -8,6 +9,7 @@ provides developers with the essential tools to quickly build and deploy their a
8
9
  * [Features](#features)
9
10
  * [Installation](#installation)
10
11
  * [Compatibility](#compatibility)
12
+ * [MacawFramework's Built-In Web Server](#macawframeworks-built-in-web-server)
11
13
  * [Usage](#usage)
12
14
  + [Basic routing: Define routes with support for GET, POST, PUT, PATCH, and DELETE HTTP methods](#basic-routing-define-routes-with-support-for-get-post-put-patch-and-delete-http-methods)
13
15
  + [Caching: Improve performance by caching responses and configuring cache invalidation](#caching-improve-performance-by-caching-responses-and-configuring-cache-invalidation)
@@ -49,6 +51,28 @@ MacawFramework is built to be highly compatible, since it uses only native Ruby
49
51
 
50
52
  - **JRuby**: MacawFramework is also compatible with JRuby, a version of Ruby that runs on the Java Virtual Machine (JVM).
51
53
 
54
+ Sure, here's a rewritten section for your README:
55
+
56
+ ## MacawFramework's Built-In Web Server
57
+
58
+ MacawFramework includes a built-in web server based on Ruby's TCPServer class, providing a lightweight yet robust solution for serving your web applications. It incorporates features such as SSL security and a thread-based architecture, offering a balance of simplicity, performance, and robustness.
59
+
60
+ ### Key Features
61
+
62
+ - **SSL Security**: Our server integrates SSL security, offering secure communication for your applications. By providing a valid SSL context, the built-in TCPServer will be wrapped in OpenSSL's SSLServer, adding an essential secure transport layer to your web server.
63
+
64
+ - **Thread-based Architecture**: We employ a thread-based model where a specified number of worker threads are used to handle client connections. Incoming connections are queued in a work queue, where they are then processed by the worker threads, ensuring fair scheduling and load distribution.
65
+
66
+ - **Thread Pool Management**: We make use of Ruby's built-in synchronization constructs, using a Mutex to safely manage the worker threads pool. A maintenance routine periodically checks the health of the worker threads, respawning any that have died, ensuring consistent server performance.
67
+
68
+ - **Graceful Shutdown**: Our server is designed to gracefully shut down when required, making sure all pending connections in the work queue are processed before closing the worker threads and the server itself. This ensures that no client requests are abruptly terminated, providing a smooth user experience.
69
+
70
+ It's worth noting that while our threading model is simple and effective, it has some limitations. The number of concurrent connections it can handle is limited by the number of worker threads, and it could be susceptible to slow clients, which could tie up a worker thread and reduce the server's capacity. However, for JRuby and TruffleRuby users, this threading model can leverage true system-level threading due to the lack of a Global Interpreter Lock (GIL), potentially providing better performance on multi-core systems and handling larger numbers of concurrent connections more efficiently.
71
+
72
+ Despite these trade-offs, MacawFramework's built-in web server offers a good balance for most web applications, particularly for small to medium scale deployments. For larger-scale applications with high concurrency demands, consider supplementing the built-in server with an event-driven architecture or utilizing a third-party server solution better suited for such scenarios.
73
+
74
+ In summary, MacawFramework's built-in web server provides a straightforward, efficient, and secure solution for running your web applications, requiring minimal configuration and making deployment a breeze.
75
+
52
76
  ## Usage
53
77
 
54
78
  ### Basic routing: Define routes with support for GET, POST, PUT, PATCH, and DELETE HTTP methods
@@ -166,6 +190,9 @@ Values for interval and start_delay are in seconds.
166
190
 
167
191
  **Caution: Defining a lot of jobs with low interval can severely degrade performance.**
168
192
 
193
+ If you want to build an application with just cron jobs, that don't need to run a web server, you can start
194
+ MacawFramework without running a web server with `start_without_server!` method, instead of `start!`.
195
+
169
196
  ### Tips
170
197
 
171
198
  - The automatic logging and log aspect are now optional. To disable them, simply start Macaw with `custom_log` set to nil.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MacawFramework
4
- VERSION = "1.1.2"
4
+ VERSION = "1.1.3"
5
5
  end
@@ -31,7 +31,7 @@ module MacawFramework
31
31
  @config = JSON.parse(File.read("application.json"))
32
32
  @port = @config["macaw"]["port"] || 8080
33
33
  @bind = @config["macaw"]["bind"] || "localhost"
34
- @threads = @config["macaw"]["threads"] || 5
34
+ @threads = @config["macaw"]["threads"] || 10
35
35
  unless @config["macaw"]["cache"].nil?
36
36
  @cache = MemoryInvalidationMiddleware.new(@config["macaw"]["cache"]["cache_invalidation"].to_i || 3_600)
37
37
  end
@@ -57,6 +57,7 @@ module MacawFramework
57
57
  # @param {String} path
58
58
  # @param {Proc} block
59
59
  # @example
60
+ #
60
61
  # macaw = MacawFramework::Macaw.new
61
62
  # macaw.get("/hello") do |context|
62
63
  # return "Hello World!", 200, { "Content-Type" => "text/plain" }
@@ -71,6 +72,8 @@ module MacawFramework
71
72
  # @param {String} path
72
73
  # @param {Boolean} cache
73
74
  # @param {Proc} block
75
+ # @example
76
+ #
74
77
  # macaw = MacawFramework::Macaw.new
75
78
  # macaw.post("/hello") do |context|
76
79
  # return "Hello World!", 200, { "Content-Type" => "text/plain" }
@@ -84,6 +87,8 @@ module MacawFramework
84
87
  # with the respective path.
85
88
  # @param {String} path
86
89
  # @param {Proc} block
90
+ # @example
91
+ #
87
92
  # macaw = MacawFramework::Macaw.new
88
93
  # macaw.put("/hello") do |context|
89
94
  # return "Hello World!", 200, { "Content-Type" => "text/plain" }
@@ -97,6 +102,8 @@ module MacawFramework
97
102
  # with the respective path.
98
103
  # @param {String} path
99
104
  # @param {Proc} block
105
+ # @example
106
+ #
100
107
  # macaw = MacawFramework::Macaw.new
101
108
  # macaw.patch("/hello") do |context|
102
109
  # return "Hello World!", 200, { "Content-Type" => "text/plain" }
@@ -110,6 +117,8 @@ module MacawFramework
110
117
  # with the respective path.
111
118
  # @param {String} path
112
119
  # @param {Proc} block
120
+ # @example
121
+ #
113
122
  # macaw = MacawFramework::Macaw.new
114
123
  # macaw.delete("/hello") do |context|
115
124
  # return "Hello World!", 200, { "Content-Type" => "text/plain" }
@@ -125,6 +134,7 @@ module MacawFramework
125
134
  # @param {String} job_name
126
135
  # @param {Proc} block
127
136
  # @example
137
+ #
128
138
  # macaw = MacawFramework::Macaw.new
129
139
  # macaw.setup_job(interval: 60, start_delay: 60, job_name: "job 1") do
130
140
  # puts "I'm a cron job that runs every minute"
@@ -163,6 +173,18 @@ module MacawFramework
163
173
  end
164
174
  end
165
175
 
176
+ ##
177
+ # This method is intended to start the framework
178
+ # without an web server. This can be useful when
179
+ # you just want to keep cron jobs running, without
180
+ # mapping any HTTP endpoints.
181
+ def start_without_server!
182
+ @macaw_log.nil? ? puts("Application starting") : @macaw_log.info("Application starting")
183
+ loop { sleep(3600) }
184
+ rescue Interrupt
185
+ @macaw_log.nil? ? puts("Macaw stop flying for some seeds.") : @macaw_log.info("Macaw stop flying for some seeds.")
186
+ end
187
+
166
188
  private
167
189
 
168
190
  def server_loop(server)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaw_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aria Diniz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prometheus-client