aranha-rails 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aranha/rails/engine.rb +5 -6
- data/lib/aranha/rails/fixtures_download.rb +27 -10
- data/lib/aranha/rails/manager.rb +2 -0
- data/lib/aranha/rails/patches/delayed_job.rb +7 -0
- data/lib/aranha/rails/process.rb +34 -0
- data/lib/aranha/rails/version.rb +1 -1
- data/lib/tasks/aranha.rake +12 -4
- metadata +25 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f04cc5c0a957bc1aec7617dc1a6e736d860d80905afa04844587b8c57dd2bd
|
4
|
+
data.tar.gz: 18c6a92f2c28731b7224ea7a99a3521c684c56e33446f29601fcab4bf2de3a68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0cf36bd155c0ccdea28701d96d385eb28d3e80a09a9a37e273b1b372f1598c27030a89d040492a707eefea98caf043972e86dc00b90e68f034cb60ef0cd59ab
|
7
|
+
data.tar.gz: 7947c879299d9ee6f0104fe7b6577a8ecc544f6bbccb59cc92f3799b951b98c2f8cd1fc7579b348d69eaa3780f70399008b901a196b42a00a15a7394bb85a2f8
|
data/lib/aranha/rails/engine.rb
CHANGED
@@ -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
|
-
|
9
|
+
include ::EacRailsUtils::EngineHelper
|
9
10
|
|
10
|
-
|
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
|
-
|
11
|
+
DEFAULT_EXTENSION = '.html'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
38
|
::Rails.logger.info(relative_path(f))
|
22
|
-
download(url(f), target(f)) if
|
39
|
+
download(url(f), target(f)) if download?
|
23
40
|
end
|
24
41
|
end
|
25
42
|
|
@@ -32,11 +49,11 @@ 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?(
|
56
|
+
relative_path(path).start_with?(prefix)
|
40
57
|
end
|
41
58
|
|
42
59
|
def fixtures_root
|
@@ -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
|
76
|
+
File.expand_path(File.basename(file, '.url') + '.source' + extension, File.dirname(file))
|
60
77
|
end
|
61
78
|
|
62
79
|
def relative_path(path)
|
data/lib/aranha/rails/manager.rb
CHANGED
@@ -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
|
@@ -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
|
data/lib/aranha/rails/version.rb
CHANGED
data/lib/tasks/aranha.rake
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
namespace(:aranha) do
|
4
4
|
desc 'Process Aranha\'s addresses.'
|
5
5
|
task process: :environment do
|
6
|
-
::Aranha::
|
6
|
+
::Aranha::Rails::Process.new.run
|
7
7
|
end
|
8
8
|
|
9
9
|
desc 'Remove all registered Aranha\'s addresses.'
|
@@ -11,13 +11,21 @@ namespace(:aranha) do
|
|
11
11
|
Rails.logger.info("Addresses deleted: #{::Aranha::Address.destroy_all.count}")
|
12
12
|
end
|
13
13
|
|
14
|
+
namespace :address do
|
15
|
+
desc 'Process a arbitrary address.'
|
16
|
+
task :process, %i[uri processor] => :environment do |_t, args|
|
17
|
+
args.processor.constantize.new(args.uri, {}).process
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
namespace :fixtures do
|
15
22
|
desc 'Download remote content for fixtures.'
|
16
23
|
task download: :environment do
|
17
24
|
::Aranha::Rails::FixturesDownload.new(
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
::Aranha::Rails::FixturesDownload::OPTION_EXTENSION => ENV['EXTENSION'],
|
26
|
+
::Aranha::Rails::FixturesDownload::OPTION_PREFIX => ENV['PREFIX'],
|
27
|
+
::Aranha::Rails::FixturesDownload::OPTION_DOWNLOAD => ENV['DOWNLOAD'].present?,
|
28
|
+
::Aranha::Rails::FixturesDownload::OPTION_PENDING => ENV['PENDING'].present?
|
21
29
|
).run
|
22
30
|
end
|
23
31
|
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.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2021-08-08 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
|
@@ -84,14 +98,14 @@ dependencies:
|
|
84
98
|
requirements:
|
85
99
|
- - "~>"
|
86
100
|
- !ruby/object:Gem::Version
|
87
|
-
version: '0.
|
101
|
+
version: '0.72'
|
88
102
|
type: :runtime
|
89
103
|
prerelease: false
|
90
104
|
version_requirements: !ruby/object:Gem::Requirement
|
91
105
|
requirements:
|
92
106
|
- - "~>"
|
93
107
|
- !ruby/object:Gem::Version
|
94
|
-
version: '0.
|
108
|
+
version: '0.72'
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
110
|
name: rails
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,20 +126,20 @@ dependencies:
|
|
112
126
|
requirements:
|
113
127
|
- - "~>"
|
114
128
|
- !ruby/object:Gem::Version
|
115
|
-
version: '0.
|
129
|
+
version: '0.3'
|
116
130
|
- - ">="
|
117
131
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.1
|
132
|
+
version: 0.3.1
|
119
133
|
type: :development
|
120
134
|
prerelease: false
|
121
135
|
version_requirements: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
137
|
- - "~>"
|
124
138
|
- !ruby/object:Gem::Version
|
125
|
-
version: '0.
|
139
|
+
version: '0.3'
|
126
140
|
- - ">="
|
127
141
|
- !ruby/object:Gem::Version
|
128
|
-
version: 0.1
|
142
|
+
version: 0.3.1
|
129
143
|
description:
|
130
144
|
email:
|
131
145
|
executables: []
|
@@ -136,6 +150,8 @@ files:
|
|
136
150
|
- lib/aranha/rails/engine.rb
|
137
151
|
- lib/aranha/rails/fixtures_download.rb
|
138
152
|
- lib/aranha/rails/manager.rb
|
153
|
+
- lib/aranha/rails/patches/delayed_job.rb
|
154
|
+
- lib/aranha/rails/process.rb
|
139
155
|
- lib/aranha/rails/version.rb
|
140
156
|
- lib/tasks/aranha.rake
|
141
157
|
homepage:
|
@@ -156,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
172
|
- !ruby/object:Gem::Version
|
157
173
|
version: '0'
|
158
174
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.1.6
|
160
176
|
signing_key:
|
161
177
|
specification_version: 4
|
162
178
|
summary: Put here de description.
|