aranha-rails 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea03bcdec3dd45159d259277c82e9caa7d6aa8469499abfff9567101a7d23e6f
4
- data.tar.gz: e25011f06e74adc37e3192e6a5fa80e849430b4b8dd0ebc7ddb0e1af3cc7ff98
3
+ metadata.gz: bbe5992eacaebe66f42310ee30ba8198d8f7533f8b7eccf6fb7cbe552884cb4a
4
+ data.tar.gz: 74be91626416ddf93d1d9702ef3e69bf91a91ea2f8bafb73cefd35745441d54c
5
5
  SHA512:
6
- metadata.gz: 458bf075dec14c64b8c63065a81bfde264420940161f7d7475ee84bf1712a86ddb04dc10f45d06d346c0fe9c9963e19d1a756898cd02505c07fe078b017576b4
7
- data.tar.gz: 6be3e41fb8f7abd3cf950bcfd55f9d0c36778c124d34e1cd0e12bd44ef5944864b164299358f176157488842228cf8d98650330718d6fa771cfa1b8b4bf468ed
6
+ metadata.gz: 4a2ffc48a555639bfc1c9960378e700359ba14319b9727a423e8aa59b901b5945bece2e68f720d87bf0c1439965a2523edc89eb1abc7d04ab09fc017bbfa18eb
7
+ data.tar.gz: 854def0c575004ee01d630d69fe0975deeaa62d486b2ebfdc3ca775144cf88e3f3bcbd67d93eb6f85da11b203c6a0239cdde626a2d2fa8e460a3c82d9f144cea
@@ -1,17 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_scaffold'
4
+ require 'eac_rails_delayed_job/engine'
4
5
 
5
6
  module Aranha
6
7
  module Rails
7
8
  class Engine < ::Rails::Engine
8
- isolate_namespace ::Aranha
9
+ include ::EacRailsUtils::EngineHelper
9
10
 
10
- initializer :append_migrations do |app|
11
- config.paths['db/migrate'].expanded.each do |expanded_path|
12
- app.config.paths['db/migrate'] << expanded_path
13
- end
14
- end
11
+ isolate_namespace ::Aranha
15
12
  end
16
13
  end
17
14
  end
15
+
16
+ require 'aranha/rails/patches/delayed_job'
@@ -3,23 +3,40 @@
3
3
  require 'aranha/parsers/base'
4
4
  require 'aranha/parsers/source_address'
5
5
  require 'aranha/parsers/source_target_fixtures'
6
+ require 'eac_ruby_utils/core_ext'
6
7
 
7
8
  module Aranha
8
9
  module Rails
9
10
  class FixturesDownload
10
- attr_reader :pending
11
+ DEFAULT_EXTENSION = '.html'
11
12
 
12
- def initialize(options)
13
- @prefix = options.fetch(:prefix)
14
- @prefix = '' if @prefix.blank?
15
- @download = options.fetch(:download)
16
- @pending = options.fetch(:pending)
13
+ enable_listable
14
+ lists.add_symbol :option, :extension, :prefix, :download, :pending
15
+
16
+ common_constructor :options do
17
+ self.options = self.class.lists.option.hash_keys_validate!(options)
18
+ end
19
+
20
+ def download?
21
+ options[OPTION_DOWNLOAD] ? true : false
22
+ end
23
+
24
+ def extension
25
+ options[OPTION_EXTENSION].if_present(DEFAULT_EXTENSION)
26
+ end
27
+
28
+ def pending?
29
+ options[OPTION_PENDING] ? true : false
30
+ end
31
+
32
+ def prefix
33
+ options[OPTION_PREFIX].if_present('')
17
34
  end
18
35
 
19
36
  def run
20
37
  url_files.each do |f|
21
- Rails.logger.info(relative_path(f))
22
- download(url(f), target(f)) if @download
38
+ ::Rails.logger.info(relative_path(f))
39
+ download(url(f), target(f)) if download?
23
40
  end
24
41
  end
25
42
 
@@ -32,19 +49,19 @@ module Aranha
32
49
  def select_path?(path)
33
50
  return false unless match_prefix_pattern(path)
34
51
 
35
- !pending || !source_exist?(path)
52
+ !pending? || !source_exist?(path)
36
53
  end
37
54
 
38
55
  def match_prefix_pattern(path)
39
- relative_path(path).start_with?(@prefix)
56
+ relative_path(path).start_with?(prefix)
40
57
  end
41
58
 
42
59
  def fixtures_root
43
- Rails.root.to_s
60
+ ::Rails.root.to_s
44
61
  end
45
62
 
46
63
  def download(url, target)
47
- Rails.logger.info "Baixando \"#{url}\"..."
64
+ ::Rails.logger.info "Baixando \"#{url}\"..."
48
65
  content = ::Aranha::Parsers::Base.new(url).content
49
66
  raise "Content is blank for \"#{url}\"" if content.blank?
50
67
 
@@ -56,7 +73,7 @@ module Aranha
56
73
  end
57
74
 
58
75
  def target(file)
59
- File.expand_path(File.basename(file, '.url') + '.source.html', File.dirname(file))
76
+ File.expand_path(File.basename(file, '.url') + '.source' + extension, File.dirname(file))
60
77
  end
61
78
 
62
79
  def relative_path(path)
@@ -9,10 +9,12 @@ module Aranha
9
9
  include ::Singleton
10
10
 
11
11
  def add_address(url, processor, extra_data = nil)
12
+ ::Rails.logger.info("Adding \"#{url}\"")
12
13
  a = ::Aranha::Address.find_or_initialize_by(url: ::Aranha::Address.sanitize_url(url))
13
14
  a.processor = processor
14
15
  a.extra_data = extra_data.to_yaml
15
16
  a.save!
17
+ a.check_scheduling
16
18
  end
17
19
 
18
20
  def addresses_count
@@ -33,6 +35,13 @@ module Aranha
33
35
  ::Rails.logger.warn(message)
34
36
  end
35
37
 
38
+ def start_points_to_addresses
39
+ super
40
+ ::Aranha::StartPoint.all.each do |sp|
41
+ add_address(sp.uri, sp.processor_class, sp.extra_data)
42
+ end
43
+ end
44
+
36
45
  def unprocessed_addresses
37
46
  ::Aranha::Address.unprocessed
38
47
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delayed_job_active_record'
4
+
5
+ model = ::Delayed::Backend::ActiveRecord::Job
6
+ model.has_one :aranha_address, class_name: 'Aranha::Address', foreign_key: :delayed_job_id,
7
+ dependent: :nullify, inverse_of: :delayed_job
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Rails
5
+ class Process
6
+ QUEUE = 'aranha'
7
+ QUEUES = [QUEUE].freeze
8
+
9
+ def run
10
+ run_init
11
+ run_jobs_workoff
12
+ run_close
13
+ end
14
+
15
+ private
16
+
17
+ def run_close
18
+ ::Aranha::Address.failed do |a|
19
+ ::Rails.logger.info "Failed \"#{a.url}\": #{a.last_error}"
20
+ end
21
+ raise 'Some address failed' if ::Aranha::Address.failed.any?
22
+ end
23
+
24
+ def run_init
25
+ ::Aranha::Manager.default.init
26
+ ::Aranha::Address.all.each(&:init_scheduling)
27
+ end
28
+
29
+ def run_jobs_workoff
30
+ ::Delayed::Worker.new(exit_on_complete: true, queues: QUEUES).start
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aranha
4
4
  module Rails
5
- VERSION = '0.1.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@
3
3
  namespace(:aranha) do
4
4
  desc 'Process Aranha\'s addresses.'
5
5
  task process: :environment do
6
- ::Aranha::Processor.new
6
+ ::Aranha::Rails::Process.new.run
7
7
  end
8
8
 
9
9
  desc 'Remove all registered Aranha\'s addresses.'
@@ -15,9 +15,10 @@ namespace(:aranha) do
15
15
  desc 'Download remote content for fixtures.'
16
16
  task download: :environment do
17
17
  ::Aranha::Rails::FixturesDownload.new(
18
- prefix: ENV['PREFIX'],
19
- download: ENV['DOWNLOAD'].present?,
20
- pending: ENV['PENDING'].present?
18
+ ::Aranha::Rails::FixturesDownload::OPTION_EXTENSION => ENV['EXTENSION'],
19
+ ::Aranha::Rails::FixturesDownload::OPTION_PREFIX => ENV['PREFIX'],
20
+ ::Aranha::Rails::FixturesDownload::OPTION_DOWNLOAD => ENV['DOWNLOAD'].present?,
21
+ ::Aranha::Rails::FixturesDownload::OPTION_PENDING => ENV['PENDING'].present?
21
22
  ).run
22
23
  end
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aranha-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-28 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_scaffold
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: eac_rails_delayed_job
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.1'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.1'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: eac_rails_utils
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -112,20 +126,14 @@ dependencies:
112
126
  requirements:
113
127
  - - "~>"
114
128
  - !ruby/object:Gem::Version
115
- version: '0.1'
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: 0.1.2
129
+ version: '0.2'
119
130
  type: :development
120
131
  prerelease: false
121
132
  version_requirements: !ruby/object:Gem::Requirement
122
133
  requirements:
123
134
  - - "~>"
124
135
  - !ruby/object:Gem::Version
125
- version: '0.1'
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- version: 0.1.2
136
+ version: '0.2'
129
137
  description:
130
138
  email:
131
139
  executables: []
@@ -136,6 +144,8 @@ files:
136
144
  - lib/aranha/rails/engine.rb
137
145
  - lib/aranha/rails/fixtures_download.rb
138
146
  - lib/aranha/rails/manager.rb
147
+ - lib/aranha/rails/patches/delayed_job.rb
148
+ - lib/aranha/rails/process.rb
139
149
  - lib/aranha/rails/version.rb
140
150
  - lib/tasks/aranha.rake
141
151
  homepage:
@@ -156,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
166
  - !ruby/object:Gem::Version
157
167
  version: '0'
158
168
  requirements: []
159
- rubygems_version: 3.0.8
169
+ rubygems_version: 3.1.6
160
170
  signing_key:
161
171
  specification_version: 4
162
172
  summary: Put here de description.