fractor 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +27 -11
- data/lib/fractor/supervisor.rb +13 -39
- data/lib/fractor/version.rb +1 -1
- data/lib/fractor/worker.rb +5 -0
- data/lib/fractor/wrapped_ractor.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a3fc9be0fb1d8993186e56bbef30b33396314e878f8a9ea3d31d79efd3c46f06
         | 
| 4 | 
            +
              data.tar.gz: 8edb3ff38f5c054d9c1e477bfb799605fd4827eb679dc10db224ad1eb45e8d64
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 17fbad9c566525c9b01ccd8f613a6fe2eb2be62298894fc4ae636736ad678f3d1c46fbf49cce5e84d6e3584cc0a5e31ce06f92a994f2a3b92e58cceedabafcbc
         | 
| 7 | 
            +
              data.tar.gz: a33d27eb70ffbd8769c6db1f5484788d0b187b5c1feb33ba65602579a2ecc17c3c14be6654ad74c414a63cf9b5d19a818bd462293eca0ca13bfd1f92272760f1
         | 
    
        data/.rubocop_todo.yml
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # This configuration was generated by
         | 
| 2 2 | 
             
            # `rubocop --auto-gen-config`
         | 
| 3 | 
            -
            # on 2025-05- | 
| 3 | 
            +
            # on 2025-05-08 09:25:37 UTC using RuboCop version 1.75.5.
         | 
| 4 4 | 
             
            # The point is for the user to remove these configuration records
         | 
| 5 5 | 
             
            # one by one as the offenses are removed from the code base.
         | 
| 6 6 | 
             
            # Note that changes in the inspected code, or installation of new
         | 
| @@ -14,6 +14,11 @@ Lint/ConstantDefinitionInBlock: | |
| 14 14 | 
             
                - 'spec/fractor/integration_spec.rb'
         | 
| 15 15 | 
             
                - 'spec/fractor/work_spec.rb'
         | 
| 16 16 |  | 
| 17 | 
            +
            # Offense count: 1
         | 
| 18 | 
            +
            Lint/DuplicateMethods:
         | 
| 19 | 
            +
              Exclude:
         | 
| 20 | 
            +
                - 'lib/fractor/supervisor.rb'
         | 
| 21 | 
            +
             | 
| 17 22 | 
             
            # Offense count: 1
         | 
| 18 23 | 
             
            Lint/HashCompareByIdentity:
         | 
| 19 24 | 
             
              Exclude:
         | 
| @@ -30,36 +35,41 @@ Lint/RescueException: | |
| 30 35 | 
             
              Exclude:
         | 
| 31 36 | 
             
                - 'lib/fractor/wrapped_ractor.rb'
         | 
| 32 37 |  | 
| 33 | 
            -
            # Offense count:  | 
| 38 | 
            +
            # Offense count: 18
         | 
| 34 39 | 
             
            # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
         | 
| 35 40 | 
             
            Metrics/AbcSize:
         | 
| 36 | 
            -
              Max:  | 
| 41 | 
            +
              Max: 98
         | 
| 37 42 |  | 
| 38 | 
            -
            # Offense count:  | 
| 43 | 
            +
            # Offense count: 9
         | 
| 39 44 | 
             
            # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
         | 
| 40 45 | 
             
            # AllowedMethods: refine
         | 
| 41 46 | 
             
            Metrics/BlockLength:
         | 
| 42 | 
            -
              Max:  | 
| 47 | 
            +
              Max: 101
         | 
| 43 48 |  | 
| 44 49 | 
             
            # Offense count: 2
         | 
| 45 50 | 
             
            # Configuration parameters: CountComments, CountAsOne.
         | 
| 46 51 | 
             
            Metrics/ClassLength:
         | 
| 47 | 
            -
              Max:  | 
| 52 | 
            +
              Max: 159
         | 
| 48 53 |  | 
| 49 54 | 
             
            # Offense count: 3
         | 
| 50 55 | 
             
            # Configuration parameters: AllowedMethods, AllowedPatterns.
         | 
| 51 56 | 
             
            Metrics/CyclomaticComplexity:
         | 
| 52 | 
            -
              Max:  | 
| 57 | 
            +
              Max: 37
         | 
| 53 58 |  | 
| 54 | 
            -
            # Offense count:  | 
| 59 | 
            +
            # Offense count: 33
         | 
| 55 60 | 
             
            # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
         | 
| 56 61 | 
             
            Metrics/MethodLength:
         | 
| 57 | 
            -
              Max:  | 
| 62 | 
            +
              Max: 67
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            # Offense count: 1
         | 
| 65 | 
            +
            # Configuration parameters: Max, CountKeywordArgs.
         | 
| 66 | 
            +
            Metrics/ParameterLists:
         | 
| 67 | 
            +
              MaxOptionalParameters: 4
         | 
| 58 68 |  | 
| 59 69 | 
             
            # Offense count: 2
         | 
| 60 70 | 
             
            # Configuration parameters: AllowedMethods, AllowedPatterns.
         | 
| 61 71 | 
             
            Metrics/PerceivedComplexity:
         | 
| 62 | 
            -
              Max:  | 
| 72 | 
            +
              Max: 37
         | 
| 63 73 |  | 
| 64 74 | 
             
            # Offense count: 1
         | 
| 65 75 | 
             
            Security/Eval:
         | 
| @@ -74,7 +84,13 @@ Style/Documentation: | |
| 74 84 | 
             
                - 'test/**/*'
         | 
| 75 85 | 
             
                - 'examples/hierarchical_hasher/hierarchical_hasher.rb'
         | 
| 76 86 |  | 
| 77 | 
            -
            # Offense count:  | 
| 87 | 
            +
            # Offense count: 13
         | 
| 88 | 
            +
            # This cop supports safe autocorrection (--autocorrect).
         | 
| 89 | 
            +
            Style/IfUnlessModifier:
         | 
| 90 | 
            +
              Exclude:
         | 
| 91 | 
            +
                - 'lib/fractor/supervisor.rb'
         | 
| 92 | 
            +
             | 
| 93 | 
            +
            # Offense count: 6
         | 
| 78 94 | 
             
            # This cop supports safe autocorrection (--autocorrect).
         | 
| 79 95 | 
             
            # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
         | 
| 80 96 | 
             
            # URISchemes: http, https
         | 
    
        data/lib/fractor/supervisor.rb
    CHANGED
    
    | @@ -37,9 +37,7 @@ module Fractor | |
| 37 37 | 
             
                # Adds a single work item to the queue.
         | 
| 38 38 | 
             
                # The item must be an instance of Fractor::Work or a subclass.
         | 
| 39 39 | 
             
                def add_work_item(work)
         | 
| 40 | 
            -
                  unless work.is_a?(Fractor::Work)
         | 
| 41 | 
            -
                    raise ArgumentError, "#{work.class} must be an instance of Fractor::Work"
         | 
| 42 | 
            -
                  end
         | 
| 40 | 
            +
                  raise ArgumentError, "#{work.class} must be an instance of Fractor::Work" unless work.is_a?(Fractor::Work)
         | 
| 43 41 |  | 
| 44 42 | 
             
                  @work_queue << work
         | 
| 45 43 | 
             
                  @total_work_count += 1
         | 
| @@ -139,9 +137,7 @@ module Fractor | |
| 139 137 |  | 
| 140 138 | 
             
                    # Break if no active workers and queue is empty, but work remains (indicates potential issue)
         | 
| 141 139 | 
             
                    if active_ractors.empty? && @work_queue.empty? && !@continuous_mode && processed_count < @total_work_count
         | 
| 142 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 143 | 
            -
                        puts "Warning: No active workers and queue is empty, but not all work is processed. Exiting loop."
         | 
| 144 | 
            -
                      end
         | 
| 140 | 
            +
                      puts "Warning: No active workers and queue is empty, but not all work is processed. Exiting loop." if ENV["FRACTOR_DEBUG"]
         | 
| 145 141 | 
             
                      break
         | 
| 146 142 | 
             
                    end
         | 
| 147 143 |  | 
| @@ -160,30 +156,22 @@ module Fractor | |
| 160 156 | 
             
                    # Find the corresponding WrappedRactor instance
         | 
| 161 157 | 
             
                    wrapped_ractor = @ractors_map[ready_ractor_obj]
         | 
| 162 158 | 
             
                    unless wrapped_ractor
         | 
| 163 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 164 | 
            -
                        puts "Warning: Received message from unknown Ractor: #{ready_ractor_obj}. Ignoring."
         | 
| 165 | 
            -
                      end
         | 
| 159 | 
            +
                      puts "Warning: Received message from unknown Ractor: #{ready_ractor_obj}. Ignoring." if ENV["FRACTOR_DEBUG"]
         | 
| 166 160 | 
             
                      next
         | 
| 167 161 | 
             
                    end
         | 
| 168 162 |  | 
| 169 | 
            -
                    if ENV["FRACTOR_DEBUG"]
         | 
| 170 | 
            -
                      puts "Selected Ractor: #{wrapped_ractor.name}, Message Type: #{message[:type]}"
         | 
| 171 | 
            -
                    end
         | 
| 163 | 
            +
                    puts "Selected Ractor: #{wrapped_ractor.name}, Message Type: #{message[:type]}" if ENV["FRACTOR_DEBUG"]
         | 
| 172 164 |  | 
| 173 165 | 
             
                    # Process the received message
         | 
| 174 166 | 
             
                    case message[:type]
         | 
| 175 167 | 
             
                    when :initialize
         | 
| 176 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 177 | 
            -
                        puts "Ractor initialized: #{message[:processor]}"
         | 
| 178 | 
            -
                      end
         | 
| 168 | 
            +
                      puts "Ractor initialized: #{message[:processor]}" if ENV["FRACTOR_DEBUG"]
         | 
| 179 169 | 
             
                      # Send work immediately upon initialization if available
         | 
| 180 170 | 
             
                      send_next_work_if_available(wrapped_ractor)
         | 
| 181 171 | 
             
                    when :result
         | 
| 182 172 | 
             
                      # The message[:result] should be a WorkResult object
         | 
| 183 173 | 
             
                      work_result = message[:result]
         | 
| 184 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 185 | 
            -
                        puts "Completed work: #{work_result.inspect} in Ractor: #{message[:processor]}"
         | 
| 186 | 
            -
                      end
         | 
| 174 | 
            +
                      puts "Completed work: #{work_result.inspect} in Ractor: #{message[:processor]}" if ENV["FRACTOR_DEBUG"]
         | 
| 187 175 | 
             
                      @results.add_result(work_result)
         | 
| 188 176 | 
             
                      if ENV["FRACTOR_DEBUG"]
         | 
| 189 177 | 
             
                        puts "Result processed. Total processed: #{@results.results.size + @results.errors.size}"
         | 
| @@ -194,9 +182,7 @@ module Fractor | |
| 194 182 | 
             
                    when :error
         | 
| 195 183 | 
             
                      # The message[:result] should be a WorkResult object containing the error
         | 
| 196 184 | 
             
                      error_result = message[:result]
         | 
| 197 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 198 | 
            -
                        puts "Error processing work #{error_result.work&.inspect} in Ractor: #{message[:processor]}: #{error_result.error}"
         | 
| 199 | 
            -
                      end
         | 
| 185 | 
            +
                      puts "Error processing work #{error_result.work&.inspect} in Ractor: #{message[:processor]}: #{error_result.error}" if ENV["FRACTOR_DEBUG"]
         | 
| 200 186 | 
             
                      @results.add_result(error_result) # Add error to aggregator
         | 
| 201 187 | 
             
                      if ENV["FRACTOR_DEBUG"]
         | 
| 202 188 | 
             
                        puts "Error handled. Total processed: #{@results.results.size + @results.errors.size}"
         | 
| @@ -205,17 +191,13 @@ module Fractor | |
| 205 191 | 
             
                      # Send next piece of work even after an error
         | 
| 206 192 | 
             
                      send_next_work_if_available(wrapped_ractor)
         | 
| 207 193 | 
             
                    else
         | 
| 208 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 209 | 
            -
                        puts "Unknown message type received: #{message[:type]} from #{wrapped_ractor.name}"
         | 
| 210 | 
            -
                      end
         | 
| 194 | 
            +
                      puts "Unknown message type received: #{message[:type]} from #{wrapped_ractor.name}" if ENV["FRACTOR_DEBUG"]
         | 
| 211 195 | 
             
                    end
         | 
| 212 196 | 
             
                    # Update processed count for the loop condition
         | 
| 213 197 | 
             
                    processed_count = @results.results.size + @results.errors.size
         | 
| 214 198 | 
             
                  end
         | 
| 215 199 |  | 
| 216 | 
            -
                  if ENV["FRACTOR_DEBUG"]
         | 
| 217 | 
            -
                    puts "Main loop finished."
         | 
| 218 | 
            -
                  end
         | 
| 200 | 
            +
                  puts "Main loop finished." if ENV["FRACTOR_DEBUG"]
         | 
| 219 201 | 
             
                  return if @continuous_mode
         | 
| 220 202 |  | 
| 221 203 | 
             
                  return unless ENV["FRACTOR_DEBUG"]
         | 
| @@ -238,17 +220,11 @@ module Fractor | |
| 238 220 | 
             
                    if !@work_queue.empty?
         | 
| 239 221 | 
             
                      work_item = @work_queue.pop # Now directly a Work object
         | 
| 240 222 |  | 
| 241 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 242 | 
            -
                        puts "Sending next work #{work_item.inspect} to Ractor: #{wrapped_ractor.name}"
         | 
| 243 | 
            -
                      end
         | 
| 223 | 
            +
                      puts "Sending next work #{work_item.inspect} to Ractor: #{wrapped_ractor.name}" if ENV["FRACTOR_DEBUG"]
         | 
| 244 224 | 
             
                      wrapped_ractor.send(work_item) # Send the Work object
         | 
| 245 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 246 | 
            -
                        puts "Work sent to #{wrapped_ractor.name}."
         | 
| 247 | 
            -
                      end
         | 
| 225 | 
            +
                      puts "Work sent to #{wrapped_ractor.name}." if ENV["FRACTOR_DEBUG"]
         | 
| 248 226 | 
             
                    else
         | 
| 249 | 
            -
                      if ENV["FRACTOR_DEBUG"]
         | 
| 250 | 
            -
                        puts "Work queue empty. Not sending new work to Ractor #{wrapped_ractor.name}."
         | 
| 251 | 
            -
                      end
         | 
| 227 | 
            +
                      puts "Work queue empty. Not sending new work to Ractor #{wrapped_ractor.name}." if ENV["FRACTOR_DEBUG"]
         | 
| 252 228 | 
             
                      # In continuous mode, don't close workers as more work may come
         | 
| 253 229 | 
             
                      unless @continuous_mode
         | 
| 254 230 | 
             
                        # Consider closing the Ractor if the queue is empty and no more work is expected.
         | 
| @@ -260,9 +236,7 @@ module Fractor | |
| 260 236 | 
             
                      end
         | 
| 261 237 | 
             
                    end
         | 
| 262 238 | 
             
                  else
         | 
| 263 | 
            -
                    if ENV["FRACTOR_DEBUG"]
         | 
| 264 | 
            -
                      puts "Attempted to send work to an invalid or closed Ractor: #{wrapped_ractor&.name || "unknown"}."
         | 
| 265 | 
            -
                    end
         | 
| 239 | 
            +
                    puts "Attempted to send work to an invalid or closed Ractor: #{wrapped_ractor&.name || "unknown"}." if ENV["FRACTOR_DEBUG"]
         | 
| 266 240 | 
             
                    # Remove from map if found but closed
         | 
| 267 241 | 
             
                    @ractors_map.delete(wrapped_ractor.ractor) if wrapped_ractor && @ractors_map.key?(wrapped_ractor.ractor)
         | 
| 268 242 | 
             
                  end
         | 
    
        data/lib/fractor/version.rb
    CHANGED
    
    
    
        data/lib/fractor/worker.rb
    CHANGED
    
    | @@ -4,6 +4,11 @@ module Fractor | |
| 4 4 | 
             
              # Base class for defining work processors.
         | 
| 5 5 | 
             
              # Subclasses must implement the `process` method.
         | 
| 6 6 | 
             
              class Worker
         | 
| 7 | 
            +
                def initialize(name: nil, **options)
         | 
| 8 | 
            +
                  @name = name
         | 
| 9 | 
            +
                  @options = options
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 7 12 | 
             
                def process(work)
         | 
| 8 13 | 
             
                  raise NotImplementedError, "Subclasses must implement the 'process' method."
         | 
| 9 14 | 
             
                end
         | 
| @@ -25,7 +25,7 @@ module Fractor | |
| 25 25 | 
             
                    Ractor.yield({ type: :initialize, processor: name })
         | 
| 26 26 |  | 
| 27 27 | 
             
                    # Instantiate the specific worker inside the Ractor
         | 
| 28 | 
            -
                    worker = worker_cls.new
         | 
| 28 | 
            +
                    worker = worker_cls.new(name: name)
         | 
| 29 29 |  | 
| 30 30 | 
             
                    loop do
         | 
| 31 31 | 
             
                      # Ractor.receive will block until a message is received
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fractor
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ronald Tse
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2025-05- | 
| 11 | 
            +
            date: 2025-05-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: Fractor is a lightweight Ruby framework designed to simplify the process
         | 
| 14 14 | 
             
              of distributing computational work across multiple Ractors.
         |