Created
October 24, 2021 00:37
-
-
Save alassek/4e80c33faa71cd8f3ab19e03362db752 to your computer and use it in GitHub Desktop.
Revisions
-
alassek created this gist
Oct 24, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ require "global_id" module Sidekiq module GlobalIDMiddleware class Processor def call(_worker_class, job, *) job["args"].map!(&method(:process)) yield end def process(argument) argument end end class Deserializer < Processor def process(argument) if argument.to_s.start_with?("gid://") GlobalID::Locator.locate(argument) else argument end end end class Serializer < Processor def process(argument) if argument.respond_to?(:to_global_id) argument.to_global_id.to_s else argument end end end end server_middleware do |chain| chain.prepend GlobalIDMiddleware::Deserializer end client_middleware do |chain| chain.prepend GlobalIDMiddleware::Serializer end end