natswork-server 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e3e313802b887c8c1df6acb9b69088b95b80f6747d795aaf065473f99a01b65a
4
+ data.tar.gz: c578ea4a71db61f6f003b600d8b9170025f36e5a97b95eac4581252eee672d0c
5
+ SHA512:
6
+ metadata.gz: 876e45dd43cbb2ab3209a68bb348825f475758b3c2dcf30195244231e6aba2d10289a5079856bb815ea7a05b468a10cf0eacfbb37157f07f171471365fd717fe
7
+ data.tar.gz: e29dff32d4f1ad7a29629538834869c190b523d3a62e1df4a017e3c048a3775acedc5aaf016d6cd2ab776e8da850dcf4c229ff4f3ce01fd564eb43f095cddd24
data/CHANGELOG.md ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tesote.com Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # NatsWork::Server
2
+
3
+ Job processing server for the NatsWork distributed job processing system.
4
+
5
+ ## Installation
6
+
7
+ Add to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'natswork-server'
11
+ ```
12
+
13
+ And execute:
14
+
15
+ $ bundle install
16
+
17
+ ## Configuration
18
+
19
+ ```ruby
20
+ NatsWork::Server.configure do |config|
21
+ config.nats_url = ENV['NATS_URL'] || 'nats://localhost:4222'
22
+ config.concurrency = 25
23
+ config.queues = ['critical', 'default', 'low']
24
+ config.logger = Logger.new(STDOUT)
25
+ end
26
+ ```
27
+
28
+ ## Starting a Worker
29
+
30
+ ### Command Line
31
+
32
+ ```bash
33
+ # Start with default settings
34
+ natswork
35
+
36
+ # Specify queues and concurrency
37
+ natswork -q critical,default -c 10
38
+
39
+ # With config file
40
+ natswork -C config/natswork.yml
41
+ ```
42
+
43
+ ### Programmatically
44
+
45
+ ```ruby
46
+ require 'natswork/server'
47
+
48
+ worker = NatsWork::Worker.new(
49
+ queues: ['critical', 'default'],
50
+ concurrency: 10,
51
+ logger: Logger.new(STDOUT)
52
+ )
53
+
54
+ # Handle signals gracefully
55
+ trap('TERM') { worker.stop }
56
+ trap('INT') { worker.stop }
57
+
58
+ worker.start
59
+ ```
60
+
61
+ ## Worker Features
62
+
63
+ ### Concurrency
64
+
65
+ Workers process jobs concurrently using a thread pool:
66
+
67
+ ```ruby
68
+ worker = NatsWork::Worker.new(
69
+ concurrency: 25 # Number of concurrent jobs
70
+ )
71
+ ```
72
+
73
+ ### Queue Priority
74
+
75
+ Process queues in order of priority:
76
+
77
+ ```ruby
78
+ worker = NatsWork::Worker.new(
79
+ queues: ['critical', 'default', 'low'],
80
+ strict: true # Strict priority ordering
81
+ )
82
+ ```
83
+
84
+ ### Middleware
85
+
86
+ Add server-side middleware:
87
+
88
+ ```ruby
89
+ class MetricsMiddleware
90
+ def call(job, message)
91
+ start = Time.now
92
+ yield
93
+ ensure
94
+ duration = Time.now - start
95
+ StatsD.timing("job.duration", duration, tags: ["job:#{job.class.name}"])
96
+ end
97
+ end
98
+
99
+ NatsWork::Server.configure do |config|
100
+ config.server_middleware do |chain|
101
+ chain.add MetricsMiddleware
102
+ end
103
+ end
104
+ ```
105
+
106
+ ### Error Handling
107
+
108
+ Configure error handling and retries:
109
+
110
+ ```ruby
111
+ NatsWork::Server.configure do |config|
112
+ # Retry configuration
113
+ config.max_retries = 5
114
+ config.retry_backoff = :exponential
115
+
116
+ # Dead letter queue
117
+ config.enable_dead_letter = true
118
+ config.dead_letter_queue = 'failed_jobs'
119
+
120
+ # Error callbacks
121
+ config.error_handler = ->(error, job, message) {
122
+ Bugsnag.notify(error, {
123
+ job_class: job.class.name,
124
+ job_id: message['job_id']
125
+ })
126
+ }
127
+ end
128
+ ```
129
+
130
+ ## Monitoring
131
+
132
+ ### Health Checks
133
+
134
+ Built-in health check endpoint:
135
+
136
+ ```ruby
137
+ # Add health checks
138
+ NatsWork::HealthChecker.global.add_check('database') do
139
+ ActiveRecord::Base.connection.active?
140
+ end
141
+
142
+ # Check health
143
+ health = NatsWork::HealthChecker.global.report
144
+ # => { status: :healthy, checks: { ... } }
145
+ ```
146
+
147
+ ### Metrics
148
+
149
+ Track worker metrics:
150
+
151
+ ```ruby
152
+ metrics = worker.stats
153
+ # => {
154
+ # jobs_processed: 1000,
155
+ # jobs_failed: 5,
156
+ # active_jobs: 3,
157
+ # queue_latency: { default: 0.5 }
158
+ # }
159
+ ```
160
+
161
+ ### Logging
162
+
163
+ Structured logging with job context:
164
+
165
+ ```ruby
166
+ NatsWork::Server.configure do |config|
167
+ config.logger = Logger.new(STDOUT)
168
+ config.log_level = :info
169
+ config.log_format = :json # JSON structured logs
170
+ end
171
+ ```
172
+
173
+ ## Deployment
174
+
175
+ ### Systemd
176
+
177
+ ```ini
178
+ [Unit]
179
+ Description=NatsWork Worker
180
+ After=network.target
181
+
182
+ [Service]
183
+ Type=simple
184
+ User=app
185
+ WorkingDirectory=/app
186
+ ExecStart=/usr/local/bin/bundle exec natswork
187
+ Restart=always
188
+ RestartSec=3
189
+
190
+ [Install]
191
+ WantedBy=multi-user.target
192
+ ```
193
+
194
+ ### Docker
195
+
196
+ ```dockerfile
197
+ FROM ruby:3.1
198
+
199
+ WORKDIR /app
200
+ COPY Gemfile* ./
201
+ RUN bundle install
202
+
203
+ COPY . .
204
+
205
+ CMD ["bundle", "exec", "natswork"]
206
+ ```
207
+
208
+ ### Kubernetes
209
+
210
+ ```yaml
211
+ apiVersion: apps/v1
212
+ kind: Deployment
213
+ metadata:
214
+ name: natswork-worker
215
+ spec:
216
+ replicas: 3
217
+ template:
218
+ spec:
219
+ containers:
220
+ - name: worker
221
+ image: myapp/worker:latest
222
+ env:
223
+ - name: NATS_URL
224
+ value: nats://nats:4222
225
+ - name: CONCURRENCY
226
+ value: "25"
227
+ resources:
228
+ requests:
229
+ memory: "256Mi"
230
+ cpu: "500m"
231
+ limits:
232
+ memory: "512Mi"
233
+ cpu: "1000m"
234
+ ```
235
+
236
+ ## Scaling
237
+
238
+ ### Horizontal Scaling
239
+
240
+ Deploy multiple workers:
241
+
242
+ ```bash
243
+ # Start multiple workers on different machines
244
+ natswork -q default -c 25 # Machine 1
245
+ natswork -q default -c 25 # Machine 2
246
+ natswork -q default -c 25 # Machine 3
247
+ ```
248
+
249
+ ### Auto-scaling
250
+
251
+ Configure based on queue depth:
252
+
253
+ ```ruby
254
+ # Monitor queue depth
255
+ monitor = NatsWork::QueueMonitor.new
256
+ if monitor.queue_depth('default') > 1000
257
+ # Scale up workers
258
+ end
259
+ ```
260
+
261
+ ## Testing
262
+
263
+ ```ruby
264
+ require 'natswork/testing'
265
+
266
+ RSpec.describe MyJob do
267
+ it 'processes job' do
268
+ NatsWork::Testing.inline! do
269
+ MyJob.perform_async('arg1', 'arg2')
270
+ # Job runs synchronously in test
271
+ end
272
+ end
273
+ end
274
+ ```
275
+
276
+ ## API Reference
277
+
278
+ See the [API documentation](https://rubydoc.info/gems/natswork-server) for detailed class and method documentation.
279
+
280
+ ## Contributing
281
+
282
+ Bug reports and pull requests are welcome at https://github.com/yourusername/natswork.
283
+
284
+ ## License
285
+
286
+ MIT License