Class: Woods::Extractors::JobExtractor
- Inherits:
-
Object
- Object
- Woods::Extractors::JobExtractor
- Includes:
- SharedDependencyScanner, SharedUtilityMethods
- Defined in:
- lib/woods/extractors/job_extractor.rb
Overview
JobExtractor handles ActiveJob and Sidekiq job extraction.
Background jobs are critical for understanding async behavior. They often perform important business logic that would otherwise be unclear from just looking at models and controllers.
We extract:
- Queue configuration
- Retry/error handling configuration
- Arguments (the job's interface)
- What the job calls (dependencies)
- What triggers this job (reverse lookup via dependencies)
Constant Summary collapse
- JOB_DIRECTORIES =
Directories to scan for jobs
%w[ app/jobs app/workers app/sidekiq ].freeze
Constants included from SharedDependencyScanner
SharedDependencyScanner::FORM_ACTION_HELPER, SharedDependencyScanner::ROUTE_HELPER_PATTERN
Instance Method Summary collapse
-
#extract_all ⇒ Array<ExtractedUnit>
Extract all jobs in the application.
-
#extract_job_class(job_class) ⇒ ExtractedUnit?
Extract a job from its class (runtime introspection).
-
#extract_job_file(file_path) ⇒ ExtractedUnit?
Extract a job from its file.
-
#initialize ⇒ JobExtractor
constructor
A new instance of JobExtractor.
Methods included from SharedDependencyScanner
#consolidate_dependencies, #extract_constantize_targets, #scan_common_dependencies, #scan_form_dependencies, #scan_job_dependencies, #scan_mailer_dependencies, #scan_model_dependencies, #scan_navigation_dependencies, #scan_service_dependencies, #strip_line_comment, #strip_ruby_line_comments
Methods included from SharedUtilityMethods
#app_source?, #condition_label, #count_loc, #detect_entry_points, #extract_action_filter_actions, #extract_callback_conditions, #extract_class_methods, #extract_custom_errors, #extract_initialize_params, #extract_namespace, #extract_parent_class, #extract_public_methods, #find_files_in_directories, #resolve_source_location, #skip_file?
Constructor Details
#initialize ⇒ JobExtractor
Returns a new instance of JobExtractor.
37 38 39 40 |
# File 'lib/woods/extractors/job_extractor.rb', line 37 def initialize @directories = JOB_DIRECTORIES.map { |d| Rails.root.join(d) } .select(&:directory?) end |
Instance Method Details
#extract_all ⇒ Array<ExtractedUnit>
Extract all jobs in the application
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/woods/extractors/job_extractor.rb', line 45 def extract_all units = [] # File-based discovery (catches everything) find_files_in_directories(@directories).each do |file| unit = extract_job_file(file) units << unit if unit end # Also try class-based discovery for ActiveJob if defined?(ApplicationJob) seen = units.to_set(&:identifier) ApplicationJob.descendants.each do |job_class| next if seen.include?(job_class.name) unit = extract_job_class(job_class) if unit units << unit seen << unit.identifier end end end units.compact end |
#extract_job_class(job_class) ⇒ ExtractedUnit?
Extract a job from its class (runtime introspection)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/woods/extractors/job_extractor.rb', line 103 def extract_job_class(job_class) return nil if job_class.name.nil? file_path = source_file_for(job_class) source = file_path && File.exist?(file_path) ? File.read(file_path) : '' unit = ExtractedUnit.new( type: :job, identifier: job_class.name, file_path: file_path ) unit.namespace = extract_namespace(job_class.name) unit.source_code = annotate_source(source, job_class.name) unit. = (job_class, source) unit.dependencies = extract_dependencies(source, job_class.name) unit rescue StandardError => e Rails.logger.error("Failed to extract job #{job_class.name}: #{e.}") nil end |
#extract_job_file(file_path) ⇒ ExtractedUnit?
Extract a job from its file
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/woods/extractors/job_extractor.rb', line 75 def extract_job_file(file_path) source = File.read(file_path) class_name = extract_class_name(file_path, source) return nil unless class_name return nil unless job_file?(source) unit = ExtractedUnit.new( type: :job, identifier: class_name, file_path: file_path ) unit.namespace = extract_namespace(class_name) unit.source_code = annotate_source(source, class_name) unit. = (source, class_name) unit.dependencies = extract_dependencies(source, class_name) unit rescue StandardError => e Rails.logger.error("Failed to extract job #{file_path}: #{e.}") nil end |