tina4ruby 3.11.13 → 3.11.15
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/CHANGELOG.md +80 -80
- data/LICENSE.txt +21 -21
- data/README.md +137 -137
- data/exe/tina4ruby +5 -5
- data/lib/tina4/ai.rb +696 -696
- data/lib/tina4/api.rb +189 -189
- data/lib/tina4/auth.rb +305 -305
- data/lib/tina4/auto_crud.rb +244 -244
- data/lib/tina4/cache.rb +154 -154
- data/lib/tina4/cli.rb +1449 -1449
- data/lib/tina4/constants.rb +46 -46
- data/lib/tina4/container.rb +74 -74
- data/lib/tina4/cors.rb +74 -74
- data/lib/tina4/crud.rb +692 -692
- data/lib/tina4/database/sqlite3_adapter.rb +165 -165
- data/lib/tina4/database.rb +625 -625
- data/lib/tina4/database_result.rb +208 -208
- data/lib/tina4/debug.rb +8 -8
- data/lib/tina4/dev.rb +14 -14
- data/lib/tina4/dev_admin.rb +935 -935
- data/lib/tina4/dev_mailbox.rb +191 -191
- data/lib/tina4/drivers/firebird_driver.rb +124 -110
- data/lib/tina4/drivers/mongodb_driver.rb +561 -561
- data/lib/tina4/drivers/mssql_driver.rb +112 -112
- data/lib/tina4/drivers/mysql_driver.rb +90 -90
- data/lib/tina4/drivers/odbc_driver.rb +191 -191
- data/lib/tina4/drivers/postgres_driver.rb +116 -106
- data/lib/tina4/drivers/sqlite_driver.rb +122 -122
- data/lib/tina4/env.rb +95 -95
- data/lib/tina4/error_overlay.rb +252 -252
- data/lib/tina4/events.rb +109 -109
- data/lib/tina4/field_types.rb +154 -154
- data/lib/tina4/frond.rb +2025 -2025
- data/lib/tina4/gallery/auth/meta.json +1 -1
- data/lib/tina4/gallery/auth/src/routes/api/gallery_auth.rb +114 -114
- data/lib/tina4/gallery/database/meta.json +1 -1
- data/lib/tina4/gallery/database/src/routes/api/gallery_db.rb +43 -43
- data/lib/tina4/gallery/error-overlay/meta.json +1 -1
- data/lib/tina4/gallery/error-overlay/src/routes/api/gallery_crash.rb +17 -17
- data/lib/tina4/gallery/orm/meta.json +1 -1
- data/lib/tina4/gallery/orm/src/routes/api/gallery_products.rb +16 -16
- data/lib/tina4/gallery/queue/meta.json +1 -1
- data/lib/tina4/gallery/queue/src/routes/api/gallery_queue.rb +325 -325
- data/lib/tina4/gallery/rest-api/meta.json +1 -1
- data/lib/tina4/gallery/rest-api/src/routes/api/gallery_hello.rb +14 -14
- data/lib/tina4/gallery/templates/meta.json +1 -1
- data/lib/tina4/gallery/templates/src/routes/gallery_page.rb +12 -12
- data/lib/tina4/gallery/templates/src/templates/gallery_page.twig +257 -257
- data/lib/tina4/graphql.rb +966 -966
- data/lib/tina4/health.rb +39 -39
- data/lib/tina4/html_element.rb +170 -170
- data/lib/tina4/job.rb +80 -80
- data/lib/tina4/localization.rb +168 -168
- data/lib/tina4/log.rb +203 -203
- data/lib/tina4/mcp.rb +696 -696
- data/lib/tina4/messenger.rb +587 -587
- data/lib/tina4/metrics.rb +793 -793
- data/lib/tina4/middleware.rb +445 -445
- data/lib/tina4/migration.rb +451 -451
- data/lib/tina4/orm.rb +790 -790
- data/lib/tina4/public/css/tina4.css +2463 -2463
- data/lib/tina4/public/css/tina4.min.css +1 -1
- data/lib/tina4/public/images/logo.svg +5 -5
- data/lib/tina4/public/js/frond.min.js +2 -2
- data/lib/tina4/public/js/tina4-dev-admin.js +565 -565
- data/lib/tina4/public/js/tina4-dev-admin.min.js +480 -480
- data/lib/tina4/public/js/tina4.min.js +92 -92
- data/lib/tina4/public/js/tina4js.min.js +48 -48
- data/lib/tina4/public/swagger/index.html +90 -90
- data/lib/tina4/public/swagger/oauth2-redirect.html +63 -63
- data/lib/tina4/query_builder.rb +380 -380
- data/lib/tina4/queue.rb +366 -366
- data/lib/tina4/queue_backends/kafka_backend.rb +80 -80
- data/lib/tina4/queue_backends/lite_backend.rb +298 -298
- data/lib/tina4/queue_backends/mongo_backend.rb +126 -126
- data/lib/tina4/queue_backends/rabbitmq_backend.rb +73 -73
- data/lib/tina4/rack_app.rb +817 -817
- data/lib/tina4/rate_limiter.rb +130 -130
- data/lib/tina4/request.rb +268 -255
- data/lib/tina4/response.rb +346 -346
- data/lib/tina4/response_cache.rb +551 -551
- data/lib/tina4/router.rb +406 -406
- data/lib/tina4/scss/tina4css/_alerts.scss +34 -34
- data/lib/tina4/scss/tina4css/_badges.scss +22 -22
- data/lib/tina4/scss/tina4css/_buttons.scss +69 -69
- data/lib/tina4/scss/tina4css/_cards.scss +49 -49
- data/lib/tina4/scss/tina4css/_forms.scss +156 -156
- data/lib/tina4/scss/tina4css/_grid.scss +81 -81
- data/lib/tina4/scss/tina4css/_modals.scss +84 -84
- data/lib/tina4/scss/tina4css/_nav.scss +149 -149
- data/lib/tina4/scss/tina4css/_reset.scss +94 -94
- data/lib/tina4/scss/tina4css/_tables.scss +54 -54
- data/lib/tina4/scss/tina4css/_typography.scss +55 -55
- data/lib/tina4/scss/tina4css/_utilities.scss +197 -197
- data/lib/tina4/scss/tina4css/_variables.scss +117 -117
- data/lib/tina4/scss/tina4css/base.scss +1 -1
- data/lib/tina4/scss/tina4css/colors.scss +48 -48
- data/lib/tina4/scss/tina4css/tina4.scss +17 -17
- data/lib/tina4/scss_compiler.rb +178 -178
- data/lib/tina4/seeder.rb +567 -567
- data/lib/tina4/service_runner.rb +303 -303
- data/lib/tina4/session.rb +297 -297
- data/lib/tina4/session_handlers/database_handler.rb +72 -72
- data/lib/tina4/session_handlers/file_handler.rb +67 -67
- data/lib/tina4/session_handlers/mongo_handler.rb +49 -49
- data/lib/tina4/session_handlers/redis_handler.rb +43 -43
- data/lib/tina4/session_handlers/valkey_handler.rb +43 -43
- data/lib/tina4/shutdown.rb +84 -84
- data/lib/tina4/sql_translation.rb +158 -158
- data/lib/tina4/swagger.rb +124 -124
- data/lib/tina4/template.rb +894 -894
- data/lib/tina4/templates/base.twig +26 -26
- data/lib/tina4/templates/errors/302.twig +14 -14
- data/lib/tina4/templates/errors/401.twig +9 -9
- data/lib/tina4/templates/errors/403.twig +29 -29
- data/lib/tina4/templates/errors/404.twig +29 -29
- data/lib/tina4/templates/errors/500.twig +38 -38
- data/lib/tina4/templates/errors/502.twig +9 -9
- data/lib/tina4/templates/errors/503.twig +12 -12
- data/lib/tina4/templates/errors/base.twig +37 -37
- data/lib/tina4/test_client.rb +159 -159
- data/lib/tina4/testing.rb +340 -340
- data/lib/tina4/validator.rb +174 -174
- data/lib/tina4/version.rb +1 -1
- data/lib/tina4/webserver.rb +312 -312
- data/lib/tina4/websocket.rb +343 -343
- data/lib/tina4/websocket_backplane.rb +190 -190
- data/lib/tina4/wsdl.rb +564 -564
- data/lib/tina4.rb +458 -458
- data/lib/tina4ruby.rb +4 -4
- metadata +3 -3
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Tina4
|
|
4
|
-
module QueueBackends
|
|
5
|
-
class MongoBackend
|
|
6
|
-
def initialize(options = {})
|
|
7
|
-
require "mongo"
|
|
8
|
-
|
|
9
|
-
uri = options[:uri] || ENV["TINA4_MONGO_URI"]
|
|
10
|
-
host = options[:host] || ENV.fetch("TINA4_MONGO_HOST", "localhost")
|
|
11
|
-
port = (options[:port] || ENV.fetch("TINA4_MONGO_PORT", 27017)).to_i
|
|
12
|
-
username = options[:username] || ENV["TINA4_MONGO_USERNAME"]
|
|
13
|
-
password = options[:password] || ENV["TINA4_MONGO_PASSWORD"]
|
|
14
|
-
db_name = options[:db] || ENV.fetch("TINA4_MONGO_DB", "tina4")
|
|
15
|
-
@collection_name = options[:collection] || ENV.fetch("TINA4_MONGO_COLLECTION", "tina4_queue")
|
|
16
|
-
|
|
17
|
-
if uri
|
|
18
|
-
@client = Mongo::Client.new(uri)
|
|
19
|
-
else
|
|
20
|
-
conn_options = { database: db_name }
|
|
21
|
-
conn_options[:user] = username if username
|
|
22
|
-
conn_options[:password] = password if password
|
|
23
|
-
@client = Mongo::Client.new(["#{host}:#{port}"], conn_options)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
@db = @client.database
|
|
27
|
-
create_indexes
|
|
28
|
-
rescue LoadError
|
|
29
|
-
raise "MongoDB backend requires the 'mongo' gem. Install with: gem install mongo"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def enqueue(message)
|
|
33
|
-
collection.insert_one(
|
|
34
|
-
_id: message.id,
|
|
35
|
-
topic: message.topic,
|
|
36
|
-
payload: message.payload,
|
|
37
|
-
created_at: message.created_at.utc,
|
|
38
|
-
attempts: message.attempts,
|
|
39
|
-
status: "pending"
|
|
40
|
-
)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def dequeue(topic)
|
|
44
|
-
doc = collection.find_one_and_update(
|
|
45
|
-
{ topic: topic, status: "pending" },
|
|
46
|
-
{ "$set" => { status: "processing" } },
|
|
47
|
-
sort: { created_at: 1 },
|
|
48
|
-
return_document: :after
|
|
49
|
-
)
|
|
50
|
-
return nil unless doc
|
|
51
|
-
|
|
52
|
-
Tina4::Job.new(
|
|
53
|
-
topic: doc["topic"],
|
|
54
|
-
payload: doc["payload"],
|
|
55
|
-
id: doc["_id"]
|
|
56
|
-
)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def acknowledge(message)
|
|
60
|
-
collection.delete_one(_id: message.id)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def requeue(message)
|
|
64
|
-
collection.find_one_and_update(
|
|
65
|
-
{ _id: message.id },
|
|
66
|
-
{ "$set" => { status: "pending" }, "$inc" => { attempts: 1 } },
|
|
67
|
-
upsert: true
|
|
68
|
-
)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def dead_letter(message)
|
|
72
|
-
collection.find_one_and_update(
|
|
73
|
-
{ _id: message.id },
|
|
74
|
-
{ "$set" => { status: "dead", topic: "#{message.topic}.dead_letter" } },
|
|
75
|
-
upsert: true
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def size(topic)
|
|
80
|
-
collection.count_documents(topic: topic, status: "pending")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def dead_letters(topic, max_retries: 3)
|
|
84
|
-
collection.find(topic: "#{topic}.dead_letter", status: "dead").map do |doc|
|
|
85
|
-
Tina4::Job.new(
|
|
86
|
-
topic: doc["topic"],
|
|
87
|
-
payload: doc["payload"],
|
|
88
|
-
id: doc["_id"]
|
|
89
|
-
)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def purge(topic, status)
|
|
94
|
-
result = collection.delete_many(topic: topic, status: status.to_s)
|
|
95
|
-
result.deleted_count
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def retry_failed(topic, max_retries: 3)
|
|
99
|
-
result = collection.update_many(
|
|
100
|
-
{ topic: topic, status: "failed", attempts: { "$lt" => max_retries } },
|
|
101
|
-
{ "$set" => { status: "pending" } }
|
|
102
|
-
)
|
|
103
|
-
result.modified_count
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def close
|
|
107
|
-
@client&.close
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
private
|
|
111
|
-
|
|
112
|
-
def collection
|
|
113
|
-
@db[@collection_name]
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def create_indexes
|
|
117
|
-
collection.indexes.create_many([
|
|
118
|
-
{ key: { topic: 1, status: 1, created_at: 1 } },
|
|
119
|
-
{ key: { topic: 1, status: 1, attempts: 1 } }
|
|
120
|
-
])
|
|
121
|
-
rescue Mongo::Error => e
|
|
122
|
-
Tina4::Log.warning("MongoDB index creation failed: #{e.message}")
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tina4
|
|
4
|
+
module QueueBackends
|
|
5
|
+
class MongoBackend
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
require "mongo"
|
|
8
|
+
|
|
9
|
+
uri = options[:uri] || ENV["TINA4_MONGO_URI"]
|
|
10
|
+
host = options[:host] || ENV.fetch("TINA4_MONGO_HOST", "localhost")
|
|
11
|
+
port = (options[:port] || ENV.fetch("TINA4_MONGO_PORT", 27017)).to_i
|
|
12
|
+
username = options[:username] || ENV["TINA4_MONGO_USERNAME"]
|
|
13
|
+
password = options[:password] || ENV["TINA4_MONGO_PASSWORD"]
|
|
14
|
+
db_name = options[:db] || ENV.fetch("TINA4_MONGO_DB", "tina4")
|
|
15
|
+
@collection_name = options[:collection] || ENV.fetch("TINA4_MONGO_COLLECTION", "tina4_queue")
|
|
16
|
+
|
|
17
|
+
if uri
|
|
18
|
+
@client = Mongo::Client.new(uri)
|
|
19
|
+
else
|
|
20
|
+
conn_options = { database: db_name }
|
|
21
|
+
conn_options[:user] = username if username
|
|
22
|
+
conn_options[:password] = password if password
|
|
23
|
+
@client = Mongo::Client.new(["#{host}:#{port}"], conn_options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@db = @client.database
|
|
27
|
+
create_indexes
|
|
28
|
+
rescue LoadError
|
|
29
|
+
raise "MongoDB backend requires the 'mongo' gem. Install with: gem install mongo"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def enqueue(message)
|
|
33
|
+
collection.insert_one(
|
|
34
|
+
_id: message.id,
|
|
35
|
+
topic: message.topic,
|
|
36
|
+
payload: message.payload,
|
|
37
|
+
created_at: message.created_at.utc,
|
|
38
|
+
attempts: message.attempts,
|
|
39
|
+
status: "pending"
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def dequeue(topic)
|
|
44
|
+
doc = collection.find_one_and_update(
|
|
45
|
+
{ topic: topic, status: "pending" },
|
|
46
|
+
{ "$set" => { status: "processing" } },
|
|
47
|
+
sort: { created_at: 1 },
|
|
48
|
+
return_document: :after
|
|
49
|
+
)
|
|
50
|
+
return nil unless doc
|
|
51
|
+
|
|
52
|
+
Tina4::Job.new(
|
|
53
|
+
topic: doc["topic"],
|
|
54
|
+
payload: doc["payload"],
|
|
55
|
+
id: doc["_id"]
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def acknowledge(message)
|
|
60
|
+
collection.delete_one(_id: message.id)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def requeue(message)
|
|
64
|
+
collection.find_one_and_update(
|
|
65
|
+
{ _id: message.id },
|
|
66
|
+
{ "$set" => { status: "pending" }, "$inc" => { attempts: 1 } },
|
|
67
|
+
upsert: true
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def dead_letter(message)
|
|
72
|
+
collection.find_one_and_update(
|
|
73
|
+
{ _id: message.id },
|
|
74
|
+
{ "$set" => { status: "dead", topic: "#{message.topic}.dead_letter" } },
|
|
75
|
+
upsert: true
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def size(topic)
|
|
80
|
+
collection.count_documents(topic: topic, status: "pending")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def dead_letters(topic, max_retries: 3)
|
|
84
|
+
collection.find(topic: "#{topic}.dead_letter", status: "dead").map do |doc|
|
|
85
|
+
Tina4::Job.new(
|
|
86
|
+
topic: doc["topic"],
|
|
87
|
+
payload: doc["payload"],
|
|
88
|
+
id: doc["_id"]
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def purge(topic, status)
|
|
94
|
+
result = collection.delete_many(topic: topic, status: status.to_s)
|
|
95
|
+
result.deleted_count
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def retry_failed(topic, max_retries: 3)
|
|
99
|
+
result = collection.update_many(
|
|
100
|
+
{ topic: topic, status: "failed", attempts: { "$lt" => max_retries } },
|
|
101
|
+
{ "$set" => { status: "pending" } }
|
|
102
|
+
)
|
|
103
|
+
result.modified_count
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def close
|
|
107
|
+
@client&.close
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
def collection
|
|
113
|
+
@db[@collection_name]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def create_indexes
|
|
117
|
+
collection.indexes.create_many([
|
|
118
|
+
{ key: { topic: 1, status: 1, created_at: 1 } },
|
|
119
|
+
{ key: { topic: 1, status: 1, attempts: 1 } }
|
|
120
|
+
])
|
|
121
|
+
rescue Mongo::Error => e
|
|
122
|
+
Tina4::Log.warning("MongoDB index creation failed: #{e.message}")
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Tina4
|
|
4
|
-
module QueueBackends
|
|
5
|
-
class RabbitmqBackend
|
|
6
|
-
def initialize(options = {})
|
|
7
|
-
require "bunny"
|
|
8
|
-
@connection = Bunny.new(
|
|
9
|
-
host: options[:host] || "localhost",
|
|
10
|
-
port: options[:port] || 5672,
|
|
11
|
-
username: options[:username] || "guest",
|
|
12
|
-
password: options[:password] || "guest",
|
|
13
|
-
vhost: options[:vhost] || "/"
|
|
14
|
-
)
|
|
15
|
-
@connection.start
|
|
16
|
-
@channel = @connection.create_channel
|
|
17
|
-
@queues = {}
|
|
18
|
-
@exchanges = {}
|
|
19
|
-
rescue LoadError
|
|
20
|
-
raise "RabbitMQ backend requires the 'bunny' gem. Install with: gem install bunny"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def enqueue(message)
|
|
24
|
-
queue = get_queue(message.topic)
|
|
25
|
-
queue.publish(message.to_json, persistent: true)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def dequeue(topic)
|
|
29
|
-
queue = get_queue(topic)
|
|
30
|
-
delivery_info, _properties, payload = queue.pop
|
|
31
|
-
return nil unless payload
|
|
32
|
-
|
|
33
|
-
data = JSON.parse(payload)
|
|
34
|
-
msg = Tina4::Job.new(
|
|
35
|
-
topic: data["topic"],
|
|
36
|
-
payload: data["payload"],
|
|
37
|
-
id: data["id"]
|
|
38
|
-
)
|
|
39
|
-
@last_delivery_tag = delivery_info.delivery_tag
|
|
40
|
-
msg
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def acknowledge(_message)
|
|
44
|
-
@channel.acknowledge(@last_delivery_tag) if @last_delivery_tag
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def requeue(message)
|
|
48
|
-
enqueue(message)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def dead_letter(message)
|
|
52
|
-
dlq = get_queue("#{message.topic}.dead_letter")
|
|
53
|
-
dlq.publish(message.to_json, persistent: true)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def size(topic)
|
|
57
|
-
queue = get_queue(topic)
|
|
58
|
-
queue.message_count
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def close
|
|
62
|
-
@channel&.close
|
|
63
|
-
@connection&.close
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
|
|
68
|
-
def get_queue(topic)
|
|
69
|
-
@queues[topic] ||= @channel.queue(topic, durable: true)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tina4
|
|
4
|
+
module QueueBackends
|
|
5
|
+
class RabbitmqBackend
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
require "bunny"
|
|
8
|
+
@connection = Bunny.new(
|
|
9
|
+
host: options[:host] || "localhost",
|
|
10
|
+
port: options[:port] || 5672,
|
|
11
|
+
username: options[:username] || "guest",
|
|
12
|
+
password: options[:password] || "guest",
|
|
13
|
+
vhost: options[:vhost] || "/"
|
|
14
|
+
)
|
|
15
|
+
@connection.start
|
|
16
|
+
@channel = @connection.create_channel
|
|
17
|
+
@queues = {}
|
|
18
|
+
@exchanges = {}
|
|
19
|
+
rescue LoadError
|
|
20
|
+
raise "RabbitMQ backend requires the 'bunny' gem. Install with: gem install bunny"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def enqueue(message)
|
|
24
|
+
queue = get_queue(message.topic)
|
|
25
|
+
queue.publish(message.to_json, persistent: true)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def dequeue(topic)
|
|
29
|
+
queue = get_queue(topic)
|
|
30
|
+
delivery_info, _properties, payload = queue.pop
|
|
31
|
+
return nil unless payload
|
|
32
|
+
|
|
33
|
+
data = JSON.parse(payload)
|
|
34
|
+
msg = Tina4::Job.new(
|
|
35
|
+
topic: data["topic"],
|
|
36
|
+
payload: data["payload"],
|
|
37
|
+
id: data["id"]
|
|
38
|
+
)
|
|
39
|
+
@last_delivery_tag = delivery_info.delivery_tag
|
|
40
|
+
msg
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def acknowledge(_message)
|
|
44
|
+
@channel.acknowledge(@last_delivery_tag) if @last_delivery_tag
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def requeue(message)
|
|
48
|
+
enqueue(message)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def dead_letter(message)
|
|
52
|
+
dlq = get_queue("#{message.topic}.dead_letter")
|
|
53
|
+
dlq.publish(message.to_json, persistent: true)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def size(topic)
|
|
57
|
+
queue = get_queue(topic)
|
|
58
|
+
queue.message_count
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def close
|
|
62
|
+
@channel&.close
|
|
63
|
+
@connection&.close
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def get_queue(topic)
|
|
69
|
+
@queues[topic] ||= @channel.queue(topic, durable: true)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|