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

Adiciona perform_in_entity para workers e os refatora #43

Closed

Conversation

manoelneto
Copy link

A grande motivação é evitar repetição do código de alteração da entidade e testa-lo.

Descrição

Cria um EntityWorker
O primeiro argumento de um EntityWorker deve ser o entity_id. O EntityWorker sobrescreve o perform, utiliza o using_connection e chama o método perform_in_entity (sem o entity_id, que é desnecessário)
Adiciona o método perform_current_entity para a classe para executar o perform passando a entidade atual.
Refatora o código para incluir o worker e alterar o método perform para perform_in_entity

Contexto e motivação

Evita duplicação, portanto melhora manutenção
Adiciona testes na mudança ao entity, o que garante que o código será executado no contexto da entidade
Issue #42

Tipos de alterações

  • ✅ Nova feature (Não quebra outras funcionalidades e adiciona funcionalidades)

@sourcelevel-bot
Copy link

Hello, @manoelneto! This is your first Pull Request that will be reviewed by SourceLevel, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

synchronization.mark_as_error!('Ocorreu um erro desconhecido.')
begin
TeachersSynchronizer.synchronize!(synchronization, worker_batch, years)
rescue IeducarApi::Base::ApiError => e

Choose a reason for hiding this comment

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

TeachersSynchronizerWorker#perform_in_entity has the variable name 'e'

Read more about it here.

synchronization.mark_as_error!('Ocorreu um erro desconhecido.')
begin
KnowledgeAreasSynchronizer.synchronize!(synchronization, worker_batch)
rescue IeducarApi::Base::ApiError => e

Choose a reason for hiding this comment

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

KnowledgeAreasSynchronizerWorker#perform_in_entity has the variable name 'e'

Read more about it here.

def entity_thread_or_parentest
thread = Thread.current

while not thread.key?(:entity) and thread.parent

Choose a reason for hiding this comment

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

Favor modifier while usage when having a single-line body.

end

def current_domain
raise Exception.new("Entity not found") if self.current.blank?

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

Read more about it here.

def current_domain
raise Exception.new("Entity not found") if self.current.blank?

self.current.domain

Choose a reason for hiding this comment

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

Redundant self detected.

end

def current_domain
raise Exception.new("Entity not found") if self.current.blank?

Choose a reason for hiding this comment

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

Redundant self detected.

end

def current_domain
raise Exception.new("Entity not found") if self.current.blank?

Choose a reason for hiding this comment

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

Provide an exception class and message as arguments to raise.

def entity_thread_or_parentest
thread = Thread.current

while not thread.key?(:entity) and thread.parent

Choose a reason for hiding this comment

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

Use ! instead of not.

require 'thread_parent'

module EntitySingletoon
extend self

Choose a reason for hiding this comment

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

Use module_function instead of extend self.

entity_thread_or_parentest[:entity]
end

def with entity, &block

Choose a reason for hiding this comment

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

Use def with parentheses when there are parameters.

module EntitySingletoon
extend self

def set entity

Choose a reason for hiding this comment

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

Use def with parentheses when there are parameters.

def entity_thread_or_parentest
thread = Thread.current

while not thread.key?(:entity) and thread.parent

Choose a reason for hiding this comment

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

Use && instead of and.

begin
thread[:entity] = entity

entity.using_connection &block

Choose a reason for hiding this comment

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

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.

end

end

Choose a reason for hiding this comment

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

Trailing whitespace detected.

prev_entity = thread[:entity]
begin
thread[:entity] = entity

Choose a reason for hiding this comment

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

Trailing whitespace detected.


self.current.domain
end
end

Choose a reason for hiding this comment

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

Final newline missing.

ensure
thread[:entity] = prev_entity
end

Choose a reason for hiding this comment

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

Extra empty line detected at method body end.

RoundingTablesSynchronizer.synchronize!(synchronization, worker_batch)
rescue IeducarApi::Base::ApiError => e
synchronization.mark_as_error!(e.message)
rescue Exception => exception

Choose a reason for hiding this comment

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

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?

SpecificStepsSynchronizer.synchronize!(synchronization, worker_batch, classroom_id, api_classroom_id)
rescue IeducarApi::Base::ApiError => e
synchronization.mark_as_error!(e.message)
rescue Exception => exception

Choose a reason for hiding this comment

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

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?

DisciplinesSynchronizer.synchronize!(synchronization, worker_batch)
rescue IeducarApi::Base::ApiError => e
synchronization.mark_as_error!(e.message)
rescue Exception => exception

Choose a reason for hiding this comment

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

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?

StudentEnrollmentSynchronizer.synchronize!(synchronization, worker_batch, years, unity_api_code)
rescue IeducarApi::Base::ApiError => e
synchronization.mark_as_error!(e.message)
rescue Exception => exception

Choose a reason for hiding this comment

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

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?


entity.using_connection do
daily_frequency = DailyFrequency.find(daily_frequency_id)
DailyFrequenciesCreator.new({

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@sourcelevel-bot
Copy link

SourceLevel has finished reviewing this Pull Request and has found:

  • 53 possible new issues (including those that may have been commented here).
  • 31 fixed issues! 🎉

You can see more details about this review at https://app.sourcelevel.io/github/portabilis/i-diario/pulls/43.

@manoelneto manoelneto closed this Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant