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

Wrap enumerators to avoid JobIteration deprecation #1140

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/jobs/concerns/maintenance_tasks/task_job_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def retry_on(*, **)
def build_enumerator(_run, cursor:)
cursor ||= @run.cursor
self.cursor_position = cursor
enumerator_builder = self.enumerator_builder
@collection_enum = @task.enumerator_builder(cursor: cursor)

@collection_enum ||= case (collection = @task.collection)
Expand Down Expand Up @@ -75,6 +76,9 @@ def build_enumerator(_run, cursor:)
MSG
end

unless @collection_enum.is_a?(JobIteration.enumerator_builder::Wrapper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a risk of Wrapper constant not existing in JobIteration.enumerator_builder namespace?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it's now part of the API. If your EnumeratorBuilder doesn't have a Wrapper constant, that line in job-iteration will raise before being able to emit the deprecation warning: https://github.com/Shopify/job-iteration/blob/v1.8.0/lib/job-iteration/iteration.rb#L223
Also I think typically one would write an EnumeratorBuilder by subclassing the one from JobIteration, so it would resolve the original wrapper in those cases.

@collection_enum = enumerator_builder.wrap(enumerator_builder, @collection_enum)
end
throttle_enumerator(@collection_enum)
end

Expand Down
Loading