aranha-rails 0.3.0 → 0.7.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: b5ce68bb8da1755e2c5b3667c314ea10e556c1a8050152348d386900dfd5383e
4
- data.tar.gz: 8bedbf6e02d127b69e49c02d11cec3d9173f0b8cc4eff02bf1128ad4ad2900f2
3
+ metadata.gz: 36ba45ae4efcdde7c87ec2826a8ae37457c791a7384b4fd3cbdd349f32fe9767
4
+ data.tar.gz: fbda8a52654c3640017c0bf7e62cc5c7ef2dbf66d2c5f59d9083685629c78314
5
5
  SHA512:
6
- metadata.gz: 9cc382aefdf04bcd68f22557fda034377564e349e31f97d168ad541de8c79312edffa87fc1f7bd1198a2362bc4eb7874f32d3a946eb2d11c4b40f274580b1a68
7
- data.tar.gz: 4f7adf4bf7353a07c54a05ebba718b26c6469b3d657dcbf355aec33baccac3110e3c7f1ac7db112b22d5941e3311f9ccfadace9c42b4d6b6a1805cbf37dc5e86
6
+ metadata.gz: 5aa3e496c87dae2659430b1fe08388a4b32087a5ff3cf5835c7327e43e2fd0e2b5c945a8e4911c29cdd99bd8aada31d0e1289bb11e9f962c170ec6c230e2b7a4
7
+ data.tar.gz: cc60ef5294d2af9e2b0066d1cae61ec1c8aecd0d5eccfc005b61509282c7f39911fb9aef399c86b46c833c5a1ad7001f3fc75fa784bac60be17fb5e25864558f
@@ -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'
@@ -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
@@ -20,9 +22,9 @@ module Aranha
20
22
  end
21
23
 
22
24
  def clear_expired_addresses
23
- q = ::Aranha::Address.by_created_at_lt(Time.zone.now - 12.hours)
25
+ q = ::Aranha::Address.expired(::Time.zone.now)
24
26
  ::Rails.logger.info("Addresses expired: #{q.count}")
25
- q.destroy_all
27
+ q.each(&:destroy)
26
28
  end
27
29
 
28
30
  def log_info(message)
@@ -41,7 +43,7 @@ module Aranha
41
43
  end
42
44
 
43
45
  def unprocessed_addresses
44
- ::Aranha::Address.unprocessed
46
+ ::Aranha::Address.all.select(&:schedule?)
45
47
  end
46
48
  end
47
49
  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.3.0'
5
+ VERSION = '0.7.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.'
@@ -11,6 +11,13 @@ 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
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.3.0
4
+ version: 0.7.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: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-08-15 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.52'
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.52'
108
+ version: '0.72'
95
109
  - !ruby/object:Gem::Dependency
96
110
  name: rails
97
111
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +126,20 @@ dependencies:
112
126
  requirements:
113
127
  - - "~>"
114
128
  - !ruby/object:Gem::Version
115
- version: '0.2'
129
+ version: '0.3'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.3.1
116
133
  type: :development
117
134
  prerelease: false
118
135
  version_requirements: !ruby/object:Gem::Requirement
119
136
  requirements:
120
137
  - - "~>"
121
138
  - !ruby/object:Gem::Version
122
- version: '0.2'
139
+ version: '0.3'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.3.1
123
143
  description:
124
144
  email:
125
145
  executables: []
@@ -130,6 +150,8 @@ files:
130
150
  - lib/aranha/rails/engine.rb
131
151
  - lib/aranha/rails/fixtures_download.rb
132
152
  - lib/aranha/rails/manager.rb
153
+ - lib/aranha/rails/patches/delayed_job.rb
154
+ - lib/aranha/rails/process.rb
133
155
  - lib/aranha/rails/version.rb
134
156
  - lib/tasks/aranha.rake
135
157
  homepage:
@@ -150,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
172
  - !ruby/object:Gem::Version
151
173
  version: '0'
152
174
  requirements: []
153
- rubygems_version: 3.0.9
175
+ rubygems_version: 3.1.6
154
176
  signing_key:
155
177
  specification_version: 4
156
178
  summary: Put here de description.