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

Active Record: automatic bulk method #5

Merged
merged 4 commits into from
Sep 3, 2023

Conversation

kaspth
Copy link
Owner

@kaspth kaspth commented Sep 3, 2023

In Rails 7.1, ActiveJob.perform_all_later will push out jobs in bulk to a queue, and we can make that nicer for our jobs.

Running the below now automatically adds a deliver_reminder_later_bulk to Invoice:

class Invoice < ActiveRecord::Base
  performs def deliver_reminder
    touch :reminded_at
  end
end

So users can do Invoice.all.deliver_reminder_later_bulk or Invoice.overdue.in_batches.each(&:deliver_reminder_later_bulk).

Ref: #4

Running the below now automatically adds a `deliver_reminder_later_bulk` to `Invoice`:

```ruby
class Invoice < ActiveRecord::Base
  performs def deliver_reminder
    touch :reminded_at
  end
end
```

So users can do `Invoice.all.deliver_reminder_later_bulk` or `Invoice.overdue.in_batches.each(&:deliver_reminder_later_bulk)`.
Comment on lines +85 to +93
# Override Minitest::Test#run to wrap each test in a transaction.
def run
result = nil
ActiveRecord::Base.transaction(requires_new: true) do
result = super
raise ActiveRecord::Rollback
end
result
end
Copy link
Owner Author

Choose a reason for hiding this comment

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

I had no idea it was this easy to wrap tests in a transaction!

@kaspth kaspth merged commit 629fd48 into main Sep 3, 2023
2 checks passed
@kaspth kaspth deleted the active_record-automatic-bulk-method branch September 3, 2023 19:42
@kaspth kaspth mentioned this pull request Sep 3, 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