Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
ven-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Trịnh Hoàng Phúc
ven-job
Commits
15b33b8c
Commit
15b33b8c
authored
May 13, 2020
by
Trịnh Hoàng Phúc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix review 13/05/2020.2
parent
b7c9fd57
Pipeline
#615
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
9 deletions
+4
-9
app/services/crawler_service.rb
+3
-8
lib/tasks/crawler.rake
+1
-1
No files found.
app/services/crawler_service.rb
View file @
15b33b8c
...
@@ -14,10 +14,10 @@ class CrawlerService
...
@@ -14,10 +14,10 @@ class CrawlerService
end
end
def
self
.
imports
(
job_attributes
,
company_attributes
,
cities
,
industries
)
def
self
.
imports
(
job_attributes
,
company_attributes
,
cities
,
industries
)
ActiveRecord
::
Base
.
transaction
do
raise
Exception
.
new
"Not enough data transferred"
if
job_attributes
.
nil?
||
company_attributes
.
nil?
||
cities
.
nil?
||
industries
.
nil?
raise
Exception
.
new
"Not enough data transferred"
if
job_attributes
.
nil?
||
company_attributes
.
nil?
||
cities
.
nil?
||
industries
.
nil?
job_attributes
[
:company_id
]
=
Company
.
find_or_create_by
(
company_attributes
).
id
ActiveRecord
::
Base
.
transaction
do
job
=
Job
.
find_or_create_by
(
job_attributes
)
job_attributes
[
:company_id
]
=
Company
.
find_or_create_by!
(
company_attributes
).
id
job
=
Job
.
find_or_create_by!
(
job_attributes
)
if
job
.
errors
.
full_messages
.
present?
if
job
.
errors
.
full_messages
.
present?
raise
Exception
.
new
"
#{
job
.
errors
.
full_messages
.
join
(
","
)
}
"
raise
Exception
.
new
"
#{
job
.
errors
.
full_messages
.
join
(
","
)
}
"
raise
ActiveRecord
::
Rollback
raise
ActiveRecord
::
Rollback
...
@@ -28,16 +28,12 @@ class CrawlerService
...
@@ -28,16 +28,12 @@ class CrawlerService
industries
=
industries
.
map
do
|
industry
|
industries
=
industries
.
map
do
|
industry
|
Industry
.
find_or_create_by
({
title:
industry
})
Industry
.
find_or_create_by
({
title:
industry
})
end
end
if
cities
.
length
>
0
cities
.
each
do
|
city
|
cities
.
each
do
|
city
|
job
.
cities
<<
city
job
.
cities
<<
city
end
end
end
if
industries
.
length
>
0
industries
.
each
do
|
industry
|
industries
.
each
do
|
industry
|
job
.
industries
<<
industry
job
.
industries
<<
industry
end
end
end
end
end
end
end
end
end
\ No newline at end of file
lib/tasks/crawler.rake
View file @
15b33b8c
...
@@ -78,7 +78,7 @@ namespace :crawler do
...
@@ -78,7 +78,7 @@ namespace :crawler do
industry
.
text
.
tr
(
","
,
""
).
squish
industry
.
text
.
tr
(
","
,
""
).
squish
end
end
CrawlerService
.
imports
(
job_attributes
,
company_attributes
,
cities
,
industries
)
result
=
CrawlerService
.
imports
(
job_attributes
,
company_attributes
,
cities
,
industries
)
logger
.
info
"Crawl success url :
#{
item
.
css
(
".figure .figcaption .title .job_link @href"
).
text
}
"
logger
.
info
"Crawl success url :
#{
item
.
css
(
".figure .figcaption .title .job_link @href"
).
text
}
"
rescue
Exception
=>
e
rescue
Exception
=>
e
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment