ru.Bee 2.7.4 → 2.7.5
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 +4 -4
- data/lib/db/test.db +0 -0
- data/lib/rubee/cli/bee_knowledge.json +1 -1
- data/lib/rubee/cli/db.rb +7 -1
- data/lib/rubee.rb +1 -1
- data/readme.md +153 -76
- metadata +2 -2
data/lib/rubee/cli/db.rb
CHANGED
|
@@ -39,7 +39,13 @@ module Rubee
|
|
|
39
39
|
|
|
40
40
|
def drop_tables(_argv)
|
|
41
41
|
out = Rubee::SequelObject::DB.tables.each { |table| Rubee::SequelObject::DB.drop_table(table, cascade: true) }
|
|
42
|
-
color_puts("These tables
|
|
42
|
+
color_puts("These tables have been dropped for the #{ENV['RACK_ENV']} env:", color: :cyan)
|
|
43
|
+
color_puts(out, color: :gray)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def truncate_tables(_argv)
|
|
47
|
+
out = Rubee::SequelObject::DB.tables.each { |table| Rubee::SequelObject::DB[table].truncate }
|
|
48
|
+
color_puts("These tables have been truncated for the #{ENV['RACK_ENV']} env:", color: :cyan)
|
|
43
49
|
color_puts(out, color: :gray)
|
|
44
50
|
end
|
|
45
51
|
|
data/lib/rubee.rb
CHANGED
data/readme.md
CHANGED
|
@@ -265,8 +265,12 @@ rubee db run:all
|
|
|
265
265
|
- user_id → users() on delete no_action on update no_action
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
8.
|
|
268
|
+
8. Truncating or rropping all tables can be handy during development. Be careful and make sure you pass the desired environment.
|
|
269
269
|
```bash
|
|
270
|
+
RACK_ENV=test rubee db truncate_tables
|
|
271
|
+
These tables have been truncated for the test env:
|
|
272
|
+
[:accounts, :addresses, :carrots, :clients, :comments, :users, :posts]
|
|
273
|
+
|
|
270
274
|
RACK_ENV=test rubee db drop_tables
|
|
271
275
|
These tables have been dropped for the test env:
|
|
272
276
|
[:companies, :company_clients, :services]
|
|
@@ -1247,18 +1251,19 @@ There are currently two ways to integrate background jobs into your application:
|
|
|
1247
1251
|
- [Sidekiq](#sidekiq-engine)
|
|
1248
1252
|
- [ThreadAsync](#threadasync-engine)
|
|
1249
1253
|
|
|
1250
|
-
## Sidekiq Engine
|
|
1251
1254
|
|
|
1252
|
-
##
|
|
1255
|
+
## Sidekiq engine
|
|
1256
|
+
|
|
1257
|
+
The Sidekiq adapter allows you to process background jobs using Redis and the Sidekiq gem.
|
|
1253
1258
|
|
|
1254
|
-
|
|
1259
|
+
1. Add Sidekiq to your Gemfile
|
|
1255
1260
|
|
|
1256
1261
|
```ruby
|
|
1257
1262
|
gem 'sidekiq'
|
|
1258
1263
|
gem 'rack-session' # Required for Sidekiq Web UI
|
|
1259
1264
|
```
|
|
1260
1265
|
|
|
1261
|
-
|
|
1266
|
+
2. Configure the adapter for the desired environment
|
|
1262
1267
|
|
|
1263
1268
|
```ruby
|
|
1264
1269
|
# config/base_configuration.rb
|
|
@@ -1268,15 +1273,13 @@ Rubee::Configuration.setup(env = :development) do |config|
|
|
|
1268
1273
|
end
|
|
1269
1274
|
```
|
|
1270
1275
|
|
|
1271
|
-
|
|
1276
|
+
3. Install dependencies
|
|
1272
1277
|
|
|
1273
1278
|
```bash
|
|
1274
1279
|
bundle install
|
|
1275
1280
|
```
|
|
1276
1281
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
Redis must be running before starting Sidekiq.
|
|
1282
|
+
4. Start Redis - Redis must be running before starting Sidekiq
|
|
1280
1283
|
|
|
1281
1284
|
```bash
|
|
1282
1285
|
# Start Redis server
|
|
@@ -1290,20 +1293,30 @@ redis-cli ping
|
|
|
1290
1293
|
# Should respond: PONG
|
|
1291
1294
|
```
|
|
1292
1295
|
|
|
1293
|
-
|
|
1296
|
+
5. Add Sidekiq configuration file
|
|
1294
1297
|
|
|
1295
1298
|
```yaml
|
|
1296
1299
|
# config/sidekiq.yml
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1300
|
+
:concurrency: 5
|
|
1301
|
+
:queues:
|
|
1302
|
+
- default
|
|
1303
|
+
- mailers
|
|
1304
|
+
- critical
|
|
1305
|
+
- low
|
|
1306
|
+
|
|
1307
|
+
# Redis connection
|
|
1308
|
+
:redis:
|
|
1309
|
+
url: redis://localhost:6379/0
|
|
1310
|
+
|
|
1311
|
+
# Optional: Logging
|
|
1312
|
+
:verbose: false
|
|
1313
|
+
:logfile: ./log/sidekiq.log
|
|
1314
|
+
|
|
1315
|
+
# Optional: PID file for daemon mode
|
|
1316
|
+
:pidfile: ./tmp/pids/sidekiq.pid
|
|
1304
1317
|
```
|
|
1305
1318
|
|
|
1306
|
-
|
|
1319
|
+
6. Create Sidekiq boot file
|
|
1307
1320
|
|
|
1308
1321
|
```ruby
|
|
1309
1322
|
# inits/sidekiq.rb
|
|
@@ -1321,7 +1334,7 @@ end
|
|
|
1321
1334
|
unless Object.const_defined?('Rubee')
|
|
1322
1335
|
require 'rubee'
|
|
1323
1336
|
|
|
1324
|
-
# Load environment variables
|
|
1337
|
+
# Load environment variables
|
|
1325
1338
|
require_relative 'dev.rb' if File.exist?(File.join(__dir__, 'dev.rb'))
|
|
1326
1339
|
|
|
1327
1340
|
# Trigger Rubee autoload
|
|
@@ -1329,7 +1342,7 @@ unless Object.const_defined?('Rubee')
|
|
|
1329
1342
|
end
|
|
1330
1343
|
```
|
|
1331
1344
|
|
|
1332
|
-
|
|
1345
|
+
7. Create a Sidekiq worker
|
|
1333
1346
|
|
|
1334
1347
|
```ruby
|
|
1335
1348
|
# app/workers/test_async_runner.rb
|
|
@@ -1362,28 +1375,31 @@ class TestAsyncRunner
|
|
|
1362
1375
|
end
|
|
1363
1376
|
```
|
|
1364
1377
|
|
|
1365
|
-
|
|
1378
|
+
8. Use it in your codebase
|
|
1366
1379
|
|
|
1367
1380
|
```ruby
|
|
1368
|
-
|
|
1369
|
-
TestAsyncRunner.new.perform_async(
|
|
1381
|
+
# Enqueue job to run asynchronously
|
|
1382
|
+
TestAsyncRunner.new.perform_async({
|
|
1370
1383
|
"email" => "new@new.com",
|
|
1371
1384
|
"password" => "123"
|
|
1372
|
-
)
|
|
1373
|
-
```
|
|
1385
|
+
}.to_json)
|
|
1374
1386
|
|
|
1375
|
-
|
|
1387
|
+
# Schedule job to run in 5 minutes (300 seconds)
|
|
1388
|
+
TestAsyncRunner.perform_in(300, {
|
|
1389
|
+
"email" => "new@new.com",
|
|
1390
|
+
"password" => "123"
|
|
1391
|
+
})
|
|
1376
1392
|
|
|
1377
|
-
|
|
1393
|
+
```
|
|
1378
1394
|
|
|
1379
|
-
###
|
|
1395
|
+
### Running Sidekiq
|
|
1380
1396
|
|
|
1397
|
+
Start Sidekiq in foreground mode for development:
|
|
1381
1398
|
```bash
|
|
1382
1399
|
bundle exec sidekiq -C config/sidekiq.yml -r ./inits/sidekiq.rb
|
|
1383
1400
|
```
|
|
1384
1401
|
|
|
1385
|
-
|
|
1386
|
-
|
|
1402
|
+
Start Sidekiq as daemon in background:
|
|
1387
1403
|
```bash
|
|
1388
1404
|
# Start as daemon
|
|
1389
1405
|
bundle exec sidekiq -d -C config/sidekiq.yml -r ./inits/sidekiq.rb
|
|
@@ -1395,16 +1411,17 @@ kill -TERM $(cat tmp/pids/sidekiq.pid)
|
|
|
1395
1411
|
tail -f log/sidekiq.log
|
|
1396
1412
|
```
|
|
1397
1413
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
Create convenient management scripts:
|
|
1401
|
-
|
|
1414
|
+
Create helper scripts for convenience:
|
|
1402
1415
|
```bash
|
|
1403
1416
|
# bin/sidekiq_start
|
|
1404
1417
|
#!/bin/bash
|
|
1405
1418
|
bundle exec sidekiq -d \
|
|
1406
1419
|
-C config/sidekiq.yml \
|
|
1407
1420
|
-r ./inits/sidekiq.rb \
|
|
1421
|
+
-L log/sidekiq.log \
|
|
1422
|
+
-P tmp/pids/sidekiq.pid
|
|
1423
|
+
|
|
1424
|
+
echo "✓ Sidekiq started. PID: $(cat tmp/pids/sidekiq.pid)"
|
|
1408
1425
|
```
|
|
1409
1426
|
|
|
1410
1427
|
```bash
|
|
@@ -1424,11 +1441,9 @@ Make them executable:
|
|
|
1424
1441
|
chmod +x bin/sidekiq_start bin/sidekiq_stop
|
|
1425
1442
|
```
|
|
1426
1443
|
|
|
1427
|
-
|
|
1444
|
+
### Sidekiq Web Dashboard
|
|
1428
1445
|
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
### 1. Create Sidekiq middleware
|
|
1446
|
+
Create Sidekiq middleware for the web dashboard:
|
|
1432
1447
|
|
|
1433
1448
|
```ruby
|
|
1434
1449
|
# inits/middlewares/sidekiq_middleware.rb
|
|
@@ -1490,21 +1505,65 @@ class SidekiqMiddleware
|
|
|
1490
1505
|
end
|
|
1491
1506
|
```
|
|
1492
1507
|
|
|
1493
|
-
|
|
1508
|
+
Set environment variables:
|
|
1509
|
+
```bash
|
|
1510
|
+
# .env
|
|
1511
|
+
REDIS_URL=redis://localhost:6379/0
|
|
1512
|
+
SIDEKIQ_USERNAME=admin
|
|
1513
|
+
SIDEKIQ_PASSWORD=your_secure_password
|
|
1514
|
+
SESSION_SECRET=generate_with_securerandom_hex_64
|
|
1515
|
+
```
|
|
1516
|
+
|
|
1517
|
+
Generate SESSION_SECRET:
|
|
1518
|
+
```bash
|
|
1519
|
+
ruby -e "require 'securerandom'; puts SecureRandom.hex(64)"
|
|
1520
|
+
```
|
|
1494
1521
|
|
|
1495
|
-
Start your Rubee application and visit
|
|
1522
|
+
Access the dashboard - Start your Rubee application and visit:
|
|
1496
1523
|
```
|
|
1497
|
-
http://localhost:
|
|
1524
|
+
http://localhost:9292/sidekiq
|
|
1498
1525
|
```
|
|
1499
1526
|
|
|
1500
|
-
Login with credentials from your
|
|
1527
|
+
Login with credentials from your `.env` file.
|
|
1528
|
+
|
|
1529
|
+
### Worker examples
|
|
1530
|
+
|
|
1531
|
+
Simple email worker:
|
|
1532
|
+
```ruby
|
|
1533
|
+
# app/workers/email_worker.rb
|
|
1534
|
+
class EmailWorker
|
|
1535
|
+
include Rubee::Asyncable
|
|
1536
|
+
include Sidekiq::Worker
|
|
1537
|
+
|
|
1538
|
+
sidekiq_options queue: :mailers, retry: 5
|
|
1539
|
+
|
|
1540
|
+
def perform(options)
|
|
1541
|
+
options = parse_options(options)
|
|
1501
1542
|
|
|
1502
|
-
|
|
1543
|
+
Mailer.send_email(
|
|
1544
|
+
to: options['email'],
|
|
1545
|
+
subject: options['subject'],
|
|
1546
|
+
body: options['body']
|
|
1547
|
+
)
|
|
1548
|
+
end
|
|
1503
1549
|
|
|
1504
|
-
|
|
1550
|
+
private
|
|
1505
1551
|
|
|
1506
|
-
|
|
1552
|
+
def parse_options(options)
|
|
1553
|
+
return options unless options.is_a?(String)
|
|
1554
|
+
JSON.parse(options) rescue options
|
|
1555
|
+
end
|
|
1556
|
+
end
|
|
1507
1557
|
|
|
1558
|
+
# Usage
|
|
1559
|
+
EmailWorker.new.perform_async({
|
|
1560
|
+
"email" => "user@example.com",
|
|
1561
|
+
"subject" => "Welcome!",
|
|
1562
|
+
"body" => "Hello..."
|
|
1563
|
+
}.to_json)
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
Worker with database records:
|
|
1508
1567
|
```ruby
|
|
1509
1568
|
# app/workers/booking_confirmation_worker.rb
|
|
1510
1569
|
class BookingConfirmationWorker
|
|
@@ -1537,7 +1596,7 @@ class BookingConfirmationWorker
|
|
|
1537
1596
|
end
|
|
1538
1597
|
|
|
1539
1598
|
# Usage
|
|
1540
|
-
BookingConfirmationWorker.new.perform_async(
|
|
1599
|
+
BookingConfirmationWorker.new.perform_async({
|
|
1541
1600
|
"to" => "client@example.com",
|
|
1542
1601
|
"client_name" => "John Doe",
|
|
1543
1602
|
"service_id" => 15,
|
|
@@ -1545,11 +1604,31 @@ BookingConfirmationWorker.new.perform_async(options: {
|
|
|
1545
1604
|
})
|
|
1546
1605
|
```
|
|
1547
1606
|
|
|
1548
|
-
|
|
1549
|
-
|
|
1607
|
+
### Queue priority
|
|
1608
|
+
|
|
1609
|
+
Configure queue processing priority in config/sidekiq.yml:
|
|
1610
|
+
|
|
1611
|
+
```yaml
|
|
1612
|
+
:queues:
|
|
1613
|
+
- critical # Processed first
|
|
1614
|
+
- default
|
|
1615
|
+
- mailers
|
|
1616
|
+
- low # Processed last
|
|
1617
|
+
```
|
|
1618
|
+
|
|
1619
|
+
Or with weights where higher weight means more frequently processed:
|
|
1620
|
+
|
|
1621
|
+
```yaml
|
|
1622
|
+
:queues:
|
|
1623
|
+
- [critical, 7]
|
|
1624
|
+
- [default, 5]
|
|
1625
|
+
- [mailers, 3]
|
|
1626
|
+
- [low, 1]
|
|
1627
|
+
```
|
|
1550
1628
|
|
|
1551
|
-
###
|
|
1629
|
+
### Monitoring and troubleshooting
|
|
1552
1630
|
|
|
1631
|
+
Check Sidekiq status:
|
|
1553
1632
|
```bash
|
|
1554
1633
|
# View running processes
|
|
1555
1634
|
ps aux | grep sidekiq
|
|
@@ -1561,42 +1640,40 @@ redis-cli ping
|
|
|
1561
1640
|
redis-cli LLEN queue:default
|
|
1562
1641
|
```
|
|
1563
1642
|
|
|
1564
|
-
|
|
1643
|
+
View logs:
|
|
1644
|
+
```bash
|
|
1645
|
+
# Tail Sidekiq logs
|
|
1646
|
+
tail -f log/sidekiq.log
|
|
1565
1647
|
|
|
1566
|
-
|
|
1567
|
-
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1648
|
+
# View last 100 lines
|
|
1649
|
+
tail -n 100 log/sidekiq.log
|
|
1650
|
+
```
|
|
1651
|
+
|
|
1652
|
+
Common issues - Workers not processing: Ensure Redis is running with redis-cli ping. Check Sidekiq is started with ps aux | grep sidekiq. Verify queue names match in worker and config.
|
|
1653
|
+
|
|
1654
|
+
Common issues - Authentication errors on Web UI: Ensure rack-session gem is installed. Check SESSION_SECRET is at least 64 bytes. Verify SIDEKIQ_USERNAME and SIDEKIQ_PASSWORD are set.
|
|
1655
|
+
|
|
1656
|
+
Common issues - Jobs failing: Check log/sidekiq.log for errors. View failed jobs in Web UI at /sidekiq/retries. Verify environment variables are loaded in inits/sidekiq.rb.
|
|
1570
1657
|
|
|
1571
|
-
|
|
1572
|
-
- Ensure `rack-session` gem is installed
|
|
1573
|
-
- Check SESSION_SECRET is at least 64 bytes
|
|
1574
|
-
- Verify SIDEKIQ_USERNAME and SIDEKIQ_PASSWORD are set
|
|
1658
|
+
### Best practices
|
|
1575
1659
|
|
|
1576
|
-
|
|
1577
|
-
- Check `log/sidekiq.log` for errors
|
|
1578
|
-
- View failed jobs in Web UI at `/sidekiq/retries`
|
|
1579
|
-
- Verify environment variables are loaded in `inits/sidekiq.rb`
|
|
1660
|
+
Pass IDs not objects - Use booking.id instead of the booking object itself to avoid serialization issues.
|
|
1580
1661
|
|
|
1581
|
-
|
|
1662
|
+
Keep jobs small - Each job should do one thing and do it well.
|
|
1582
1663
|
|
|
1583
|
-
|
|
1664
|
+
Make jobs idempotent - Jobs should be safe to run multiple times with the same result.
|
|
1584
1665
|
|
|
1585
|
-
|
|
1586
|
-
2. **Keep jobs small** - One job should do one thing
|
|
1587
|
-
3. **Make jobs idempotent** - Safe to run multiple times
|
|
1588
|
-
4. **Set appropriate retries** - Critical: more retries, notifications: fewer
|
|
1589
|
-
5. **Use different queues** - Separate critical from low-priority jobs
|
|
1590
|
-
6. **Handle JSON properly** - Always parse options in `perform` method
|
|
1591
|
-
7. **Monitor your queues** - Use Web UI to watch for backlogs
|
|
1666
|
+
Set appropriate retries - Use more retries for critical jobs and fewer for notifications.
|
|
1592
1667
|
|
|
1593
|
-
|
|
1668
|
+
Use different queues - Separate critical jobs from low-priority jobs using different queue names.
|
|
1594
1669
|
|
|
1595
|
-
|
|
1670
|
+
Handle JSON properly - Always parse options in the perform method to handle string arguments.
|
|
1596
1671
|
|
|
1597
|
-
-
|
|
1598
|
-
|
|
1599
|
-
-
|
|
1672
|
+
Monitor your queues - Use the Web UI to watch for backlogs and failed jobs.
|
|
1673
|
+
|
|
1674
|
+
Additional resources - Sidekiq Official Documentation at https://github.com/sidekiq/sidekiq/wiki. Best Practices guide at https://github.com/sidekiq/sidekiq/wiki/Best-Practices. Error Handling guide at https://github.com/sidekiq/sidekiq/wiki/Error-Handling.
|
|
1675
|
+
|
|
1676
|
+
[Back to content](#content)
|
|
1600
1677
|
|
|
1601
1678
|
### ThreadAsync engine
|
|
1602
1679
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ru.Bee
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.7.
|
|
4
|
+
version: 2.7.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Saltykov
|
|
@@ -305,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
305
305
|
- !ruby/object:Gem::Version
|
|
306
306
|
version: '0'
|
|
307
307
|
requirements: []
|
|
308
|
-
rubygems_version: 4.0.
|
|
308
|
+
rubygems_version: 4.0.8
|
|
309
309
|
specification_version: 4
|
|
310
310
|
summary: Fast and lightweight Ruby application server designed for minimalism and
|
|
311
311
|
flexibility
|