Skip to content
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

Merged
merged 137 commits into from
Dec 1, 2017
Merged

Pridavanie novych entit z ITMS API v2 #23

merged 137 commits into from
Dec 1, 2017

Conversation

eronisko
Copy link
Contributor

@eronisko eronisko commented Oct 5, 2017

Pridavanie novych entit z ITMS API v2 (#22)

@eronisko
Copy link
Contributor Author

eronisko commented Oct 9, 2017

@ebalgava pridal som nejake nove entity (nezrovnalost,pohladavkovyDoklad,projektovyUkazovatel) a updatol nejake starsie tabulky. Ak mas cas, bol by som zvedavy na tvoju spatnu vazbu, najma na 7fe113f#diff-f9ae8314082d8229b38da27dd6c2642d

unit = Itms::AccountsReceivableDocument.find_by(itms_id: json['id'])
return unit if unit.present?

Itms::SyncAccountsReceivableDocumentJob.perform_now(json['id'], downloader: downloader)
Copy link
Contributor Author

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.

Copy link
Member

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!
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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
@eronisko
Copy link
Contributor Author

@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.

json = downloader.get_json_from_href(itms_href)

ActiveRecord::Base.transaction do
pa = Itms::Activity.find_or_create_by!(itms_id: json['id'])
Copy link
Contributor

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'])
Copy link
Contributor

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|
Copy link
Contributor

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) }
Copy link
Contributor

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|
Copy link
Contributor

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']) }
Copy link
Contributor

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')
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activity_type = find_or_create_activity_type_by_json(activity_type_json, downloader)

scope.find_or_create_by!(
konkretny_ciel: specific_goal,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants