-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pridavanie novych entit z ITMS API v2 #23
Conversation
7cbbd67
to
7c14b1c
Compare
@ebalgava pridal som nejake nove entity ( |
app/jobs/itms_job.rb
Outdated
unit = Itms::AccountsReceivableDocument.find_by(itms_id: json['id']) | ||
return unit if unit.present? | ||
|
||
Itms::SyncAccountsReceivableDocumentJob.perform_now(json['id'], downloader: downloader) |
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.
@jsuchal Je toto OK? Ta filozofia je taka, ze objekt sa neulozi pokial nebudu ulozene vsetky jeho associated objekty. A kazdy class dostane svoj 'sync job', ktory bude (synchronne) spustat sync joby tych associated objektov.
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.
Ano toto dava zmysel pokym tam neni cyklus.
d.itms_href = json['href'] | ||
d.itms_created_at = json['createdAt'] | ||
d.itms_updated_at = json['updatedAt'] | ||
d.save! |
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.
@jsuchal Tymto (skory zapis nekompletneho zaznamu v transakcii) by som sa vyhol deadlockom (ked Objekt A potrebuje Objekt B a Objekt B potrebuje Objekt A).
Takto mozem vytvorit vztahy v self-referential join tabulkach (napr. nezrovnalost.suvisiace_nezrovnalosti
) predtym nez su tie objekty kompletne vyskladane.
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.
Asi uplne nerozumiem ako to riesi ten deadlock, kedze transakciu nevidiet pokym nie je commit.
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.
Hej, riesi to zrejme len deadlock v ramci jednej transakcie. Na paralelne transakcie budem musiet vymysliet nieco lepsie.
Applies to Itms::NrfcApplication, Itms::PaymentClaim, Itms::Project
@jsuchal spravil by si review? Funguje to uz tak ako ma (potahalo mi to cely dataset). Na zaciatku to stale robi deadlocky, ale ked uz je vacsina dat potahanych, ide to v pohode aj paralelne. Nejakych par entit (cca 45) sa cez API nezobrazuju ako by mali, takze ich to nevie stiahnut. V ITMS uz na to maju bug reporty a robia na tom. |
app/jobs/itms/sync_activity_job.rb
Outdated
json = downloader.get_json_from_href(itms_href) | ||
|
||
ActiveRecord::Base.transaction do | ||
pa = Itms::Activity.find_or_create_by!(itms_id: json['id']) |
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.
pa = Itms::Activity
co znamena pa
? (napr. toto mi je jasne ard = Itms::AccountsReceivableDocument
)
json = downloader.get_json_from_href(itms_href) | ||
|
||
ActiveRecord::Base.transaction do | ||
u = Itms::ActivityType.find_or_create_by!(itms_id: json['id']) |
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.
u = Itms::ActivityType
, preco nie at = ...
?
class Itms::SyncAllOperationalProgramsJob < ItmsJob | ||
def perform(downloader: ItmsJob::Downloader) | ||
json_list = downloader.get_json_from_href('/v2/operacneProgramy') | ||
json_list.map do |json| |
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.
preco map
a nie each
?
def perform(downloader: ItmsJob::Downloader) | ||
json = downloader.get_json_from_href('/v2/zonfp/prijate') | ||
hrefs = json.map { |item| item['href'] } | ||
hrefs.each { |href| Itms::SyncNrfcApplicationJob.perform_later(href) } |
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.
sledujem tu istu podobnost medzi SyncAll*
jobmi:
napr. Itms::SyncAllNrfcApplicationsJob
json = downloader.get_json_from_href('/v2/zonfp/prijate')
hrefs = json.map { |item| item['href'] }
hrefs.each { |href| Itms::SyncNrfcApplicationJob.perform_later(href) }
vs.
napr. Itms::SyncAllOperationalProgramsJob
json_list = downloader.get_json_from_href('/v2/operacneProgramy')
json_list.map do |json|
Itms::SyncOperationalProgramJob.perform_later(json['href'])
end
nebolo by dobre tento zapis zjednotit?
som za prvu moznost, pripadne by som upravil na:
json = downloader.get_json_from_href('/v2/zonfp/prijate')
json.each { |object| Itms::SyncNrfcApplicationJob.perform_later(object['href']) }
operational_programs_json = downloader.get_json_from_href('/v2/operacneProgramy') | ||
operational_programs_ids = operational_programs_json.map { |json| json['id'] } | ||
|
||
operational_programs_ids.map do |op_id| |
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.
preco map
?
|
||
operational_programs_ids.map do |op_id| | ||
priority_axes_json = downloader.get_json_from_href("/v2/operacneProgramy/#{op_id}/prioritneOsi") | ||
priority_axes_json.map { |json| Itms::SyncPriorityAxisJob.perform_later(json['href']) } |
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.
opat, preco map
?
@@ -0,0 +1,11 @@ | |||
class Itms::SyncAllPriorityAxesJob < ItmsJob | |||
def perform(downloader: ItmsJob::Downloader) | |||
operational_programs_json = downloader.get_json_from_href('/v2/operacneProgramy') |
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.
Zvazil by som drzat sa jednotneho pomenovania premennych, niekde mame json['href']
, inde mame item['href']
, atd. Potom niekde mame operational_programs_json = downloader.get_json_from_href(...)
, inde mame json = downloader.get_json_from_href(...)
atd.
Pre downloader.get_json_from_href(...)
/ ...['href']
by som zvolil json = ...
/ object['href']
alebo object = ...
/ pair['href']
, pozri http://json.org
typ_aktivity: activity_type | ||
) | ||
end | ||
end.flatten |
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.
tato syntax mi nesedi end.flatten
, pozri https://github.com/bbatsov/ruby-style-guide#single-line-blocks
activity_type = find_or_create_activity_type_by_json(activity_type_json, downloader) | ||
|
||
scope.find_or_create_by!( | ||
konkretny_ciel: specific_goal, |
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.
podla mna, stacia 2 medzery. pozri https://github.com/bbatsov/ruby-style-guide#no-double-indent
* Prefer each() over map() * Fix double indents * Do not chain after multi-line blocks
Pridavanie novych entit z ITMS API v2 (#22)