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

Fix return value of subscribed_task_stats #856

Merged
merged 1 commit into from
Dec 23, 2022

Conversation

fabiormoura
Copy link
Contributor

@fabiormoura fabiormoura commented Sep 12, 2022

The method subscribed_task_stats wraps almost all methods in RakeHelper but it has a bug.

For instance, the upgrade method in the same module is supposed to return a list of changed indexes in

subscribed_task_stats(output) do
indexes = indexes_from(only: only, except: except)
changed_indexes = indexes.select do |index|
index.specification.changed?
end
if changed_indexes.present?
indexes.each do |index|
if changed_indexes.include?(index)
reset_one(index, output, parallel: parallel)
else
output.puts "Skipping #{index}, the specification didn't change"
end
end
else
output.puts 'No index specification was changed'
end
changed_indexes
end

However, the wrapping method isn't returning to the caller the value of changed_indexes. Instead, it returns the result of the method output.puts which is nil.

I'm simply moving output.puts to be called within ensure so the output of the method correctly returns the result of:

ActiveSupport::Notifications.subscribed(Chewy::RakeHelper::JOURNAL_CALLBACK.curry[output], "apply_journal.chewy") do
    ActiveSupport::Notifications.subscribed(Chewy::RakeHelper::IMPORT_CALLBACK.curry[output], "import_objects.chewy", &block)
end

that would resolve to the correct value in the end when &block is evaluated.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the changelog if the new code introduces user-observable changes. See changelog entry format for details.

@fabiormoura fabiormoura changed the title Fix return value for subscribed_task_stats Fix return value of subscribed_task_stats Sep 12, 2022
@konalegi
Copy link
Contributor

hey, @fabiormoura thanks for the fix, PR looks good, but, could you please provide a spec for the subscribed_task_stats method? Thanks!

@konalegi
Copy link
Contributor

Also, please provide a changelog entry, so that will be easier to generate a release (example)

@konalegi konalegi self-requested a review December 23, 2022 07:18
@fabiormoura
Copy link
Contributor Author

Also, please provide a changelog entry, so that will be easier to generate a release (example)

Thanks for the suggestions @konalegi. I made the changes which have been amended.

@@ -4,6 +4,8 @@

### New Features

* [#856](https://github.com/toptal/chewy/pull/856): Fix return value of subscribed_task_stats used in rake tasks. ([@fabiormoura][])

### Changes

### Bugs Fixed
Copy link
Contributor

@konalegi konalegi Dec 23, 2022

Choose a reason for hiding this comment

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

I would say it's a bug fix, rather than a new feature :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was because I haven't noticed there was a specific section in this file for bug fixes but thanks for approving the PR with this small mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this has been resolved.

@konalegi
Copy link
Contributor

@fabiormoura could you please fix rubocop offenses as well? Thanks

@fabiormoura
Copy link
Contributor Author

@fabiormoura could you please fix rubocop offenses as well? Thanks

it's been fixed.

@konalegi konalegi merged commit 0ad19ab into toptal:master Dec 23, 2022
@konalegi
Copy link
Contributor

Merged, going to release it on Monday. Thanks for PR :)

cyucelen pushed a commit to cyucelen/chewy that referenced this pull request Jan 28, 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.

2 participants