-
Notifications
You must be signed in to change notification settings - Fork 125
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
Correlated async handlers #379
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
paneq
commented
Jun 22, 2018
- documentation
which help with correlating commands/events coming from async handlers. Issue: #346
for review after #375 |
in Rails 4.2.* It doesn't really test much (which was revealed by mutation testing and thus changed to :async) because it executes the job in the same thread and thus getting the metadata that we prepared for sync-handlers. So not really testing what we have in mind. We should include additional integration tests which would verify with a few other adapters for safety. Issue: #346
to be double sure that our serialization for async handlers works properly. Issue: #346 ----- ActiveJob::Base.queue_adapter global ----- Unfortunately in rails 4.2 Active job queue adapter was a class variable shared between all classes: module ActiveJob module QueueAdapter #:nodoc: extend ActiveSupport::Concern module ClassMethods mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter } def queue_adapter=(name_or_adapter) @@queue_adapter = \ case name_or_adapter when :test ActiveJob::QueueAdapters::TestAdapter.new when Symbol, String load_adapter(name_or_adapter) else name_or_adapter if name_or_adapter.respond_to?(:enqueue) end end as a result writing: class MySidekiqHandler < ActiveJob::Base self.queue_adapter = :sidekiq affected all tests :( and set the queue adapter to sidekiq for all handlers and not this one particular only. Rails 5.2 uses class_attribute from ActiveSupport: * Declare a class-level attribute whose value is inheritable by subclasses. * Subclasses can change their own value and it will not impact parent class. but we need our tests to work on both versions right now. So I decided to operate on ActiveJob::Base.queue_adapter in all test to unify the behavior between all versions that we support. ----- Sidekiq testing ----- I did not plan originally to use Sidekiq::Testing as I wanted be as close to real scenario as possible. But I could not find an easy way to run a real worker that would get the jobs from redis and process them and then quit. This seems to be good enough as we go through the serialization process: class Client alias_method :raw_push_real, :raw_push def raw_push(payloads) if Sidekiq::Testing.fake? payloads.each do |job| job = Sidekiq.load_json(Sidekiq.dump_json(job)) job.merge!('enqueued_at' => Time.now.to_f) unless job['at'] Queues.push(job['queue'], job['class'], job) end true elsif Sidekiq::Testing.inline? payloads.each do |job| klass = Sidekiq::Testing.constantize(job['class']) job['id'] ||= SecureRandom.hex(12) job_hash = Sidekiq.load_json(Sidekiq.dump_json(job)) klass.process_job(job_hash) end true else raw_push_real(payloads) end end end I run Sidekiq::Worker.drain_all in a new thread to decouple from thread-level global variables. https://github.com/mperham/sidekiq/wiki/Testing ----- STDOUT ----- Sidekiq is unhappy about Rails.env when we require it: if defined?(::Rails) && Rails.respond_to?(:env) && !Rails.env.test? puts("⛔️ WARNING: Sidekiq testing API enabled...") I reassign $stdout to mute this warning which is not of value for us.
How about for non-Rails environments? |
Right. OK, so you are focused more on making this functionality pretty
seamless in a Rails environment, but don't want to make any assumptions
outside of there. I don't have a specific agnostic implementation or helper
class in mind that could go into ruby_event_store, but will share my
thoughts once I implement this in a ROM environment, to see if any code
sharing would make sense.
On Mon, Jun 25, 2018 at 11:17 AM Robert Pankowecki ***@***.***> wrote:
@joelvh <https://github.com/joelvh> invoke correlate_with
-
https://github.com/RailsEventStore/rails_event_store/blob/master/railseventstore.org/source/docs/correlation_causation.html.md#correlating-one-event-with-another
-
https://github.com/RailsEventStore/rails_event_store/blob/master/railseventstore.org/source/docs/correlation_causation.html.md#correlating-an-event-with-a-command
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#379 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAH4SERCyYd2RzWZ6g8CQaWHi3MaMV5jks5uAP8QgaJpZM4Uz2Cx>
.
--
~Joel
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.