Skip to content

Suggestion: Add around iterate callback#445

Merged
gustavompo merged 1 commit into
mainfrom
gus/around_iterate
Jan 5, 2024
Merged

Suggestion: Add around iterate callback#445
gustavompo merged 1 commit into
mainfrom
gus/around_iterate

Conversation

@gustavompo

@gustavompo gustavompo commented Jan 2, 2024

Copy link
Copy Markdown
Contributor

There has been some circumstances that it would be great to append a callback to job iterations. More noticeably, that adds extensibility to build some generic handlers, such as metrics collection and logging.
At shopify, a particular use case that'll be especially useful is to deal with the canonical logger and long iterating jobs.

@bdewater

bdewater commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

Since you mention "metrics collection and logging" you might be interested in #338 which added the each_iteration.iteration ActiveSupport::Notifications event to subscribe to specifically for these kinds of things.

You could also bring your own LogSubscriber class for your specific logger needs.

@gustavompo

Copy link
Copy Markdown
Contributor Author

Since you mention "metrics collection and logging" you might be interested in #338 which added the each_iteration.iteration ActiveSupport::Notifications event to subscribe to specifically for these kinds of things.

You could also bring your own LogSubscriber class for your specific logger needs.

Right, thanks for the comment! Yeah those are certainly useful too, we use some of the current notifications for metrics and logging.

Apart from the main use case I'm trying to address, which re-defining the canonical logger's unit-of-work for each iteration, the PR allows also some advanced instrumentation mechanisms that, similar to the logger, rely on wrapping the execution block, e.g: Database query count and database time, captured in a given context (which under the hood also use ActiveSupport's notifications, but from active record)

@gustavompo gustavompo marked this pull request as ready for review January 4, 2024 18:02
@gustavompo gustavompo merged commit f3a89f8 into main Jan 5, 2024
@sambostock sambostock deleted the gus/around_iterate branch February 6, 2024 15:22
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.

4 participants