-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GO-128 Download messages from FS #483
Changes from 37 commits
bb0a0a0
0ac9aa8
ce6ab5b
95e9b4e
154ee47
6e6ac84
823fe35
0dbe7f0
41e10c9
47899d5
fdbe251
a32b402
8ac7511
2f935b6
351dce0
fd14363
be51628
e19f6e4
1b81b73
7d2fd3e
0747cc4
6840c4f
50ca8c5
6dbbe2c
58bfcc2
63ce7b3
a5167d9
1c38460
266ffa0
84f1650
dcfd011
5d9e89d
5d135b3
7307fae
9de9135
16dc11c
6a97f21
8474ba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Fs::MessageHelper | ||
def self.build_html_visualization(message) | ||
return [ActionController::Base.new.render_to_string('fs/messages/_submission', layout: false, locals: { message: message }), build_html_visualization_from_form(message)].compact.join('<hr>') if message.outbox? | ||
|
||
# TODO: Vieme aj lepsie identifikovat? Nejake dalsie typy v tejto kategorii neexistuju? | ||
template = if message.title.in?(['Informácia o podaní', 'Informácia o odmietnutí podania']) | ||
'fs/messages/_delivery_report' | ||
else | ||
'fs/messages/_generic_message' | ||
end | ||
|
||
ActionController::Base.new.render_to_string(template, layout: false, locals: { message: message }) | ||
end | ||
|
||
def self.build_html_visualization_from_form(message) | ||
raise 'Missing Fs::Form XSLT' unless message.form&.xslt_txt | ||
return unless message.form_object&.unsigned_content | ||
|
||
template = Nokogiri::XSLT(message.form.xslt_txt) | ||
|
||
ActionController::Base.new.render_to_string('fs/messages/_style', layout: false, locals: { message: message }) + ActionController::Base.helpers.simple_format(template.transform(message.form_object.xml_unsigned_content).to_s) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Fs | ||
class DownloadReceivedMessageJob < ApplicationJob | ||
def perform(fs_message_id, box:, fs_client: FsEnvironment.fs_client) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
return if box.messages.where("metadata ->> 'fs_message_id' = ?", fs_message_id).any? | ||
|
||
ActiveRecord::Base.transaction do | ||
fs_api = fs_client.api(api_connection: box.api_connection, box: box) | ||
|
||
raw_message = fs_api.fetch_received_message(fs_message_id) | ||
|
||
Fs::Message.create_inbox_message_with_thread!(raw_message, box: box) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Fs | ||
class DownloadSentMessageJob < ApplicationJob | ||
def perform(fs_message_id, box:, fs_client: FsEnvironment.fs_client) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
return if box.messages.where(type: [nil, 'Message']).where("metadata ->> 'fs_message_id' = ?", fs_message_id).any? | ||
|
||
ActiveRecord::Base.transaction do | ||
fs_api = fs_client.api(api_connection: box.api_connection, box: box) | ||
|
||
raw_message = fs_api.fetch_sent_message(fs_message_id) | ||
|
||
message = Fs::Message.create_outbox_message_with_thread!(raw_message, box: box) | ||
|
||
DownloadSentMessageRelatedMessagesJob.set(wait: 3.minutes).perform_later(message) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Fs | ||
class DownloadSentMessageRelatedMessagesJob < ApplicationJob | ||
def perform(outbox_message, from: nil, to: nil, fs_client: FsEnvironment.fs_client, batch_size: 25) | ||
raise unless outbox_message.box.is_a?(Fs::Box) | ||
return unless outbox_message.box.syncable? | ||
|
||
fs_api = fs_client.api(api_connection: outbox_message.box.api_connection, box: outbox_message.box) | ||
|
||
0.step do |k| | ||
received_messages = fs_api.fetch_received_messages(sent_message_id: outbox_message.metadata['fs_message_id'], page: k + 1, count: batch_size, from: from, to: to) | ||
|
||
received_messages['messages'].each do |received_message| | ||
::Fs::DownloadReceivedMessageJob.perform_later(received_message['message_id'], box: outbox_message.box) | ||
end | ||
|
||
break if received_messages['messages'].size < batch_size | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Fs | ||
class SyncAllBoxesJob < ApplicationJob | ||
def perform | ||
Fs::Box.where(syncable: true).find_each do |box| | ||
SyncBoxJob.perform_later(box) | ||
end | ||
|
||
# TODO ponastavovat v BetterUptime | ||
BetterUptimeApi.ping_heartbeat('FS_SYNC') | ||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @celuchmarek pridame heartbeat? Mozem skusit aj ja ponastavovat, ale povedz, aby som ti nebabrala do toho pripadne. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jj, môžeš pridať a nastaviť. Todo comment vyhoď, to nastavíš hneď. |
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Fs | ||
class SyncBoxJob < ApplicationJob | ||
def perform(box, from: Date.today - 1.week, to: Date.tomorrow) | ||
raise unless box.is_a?(Fs::Box) | ||
return unless box.syncable? | ||
|
||
box.messages.outbox.find_each do |outbox_message| | ||
DownloadSentMessageRelatedMessagesJob.perform_later(outbox_message, from: from, to: to) | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto tu je otvorena vec. FS API v response vracia aj
message_type
, da sa identifikovat aj podla toho (ale tiez to je trochu len take hadanie, ked nemame nejaku dokumentaciu k tomu). Nevieme ako casto sa mozu zmenit bud tieto nazvy alebomessage_type
.Samotna dorucenka si myslim, ze problem nie je (tam by som sa spolahla aj na
message_type
), ale tieto negativne verzie su narocnejsie. Nevieme ani kolko typov existuje.