Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
1989f622
Commit
1989f622
authored
9 years ago
by
Bruno Nocera Zanette
Browse files
Options
Downloads
Patches
Plain Diff
Refactor CreateRelation Task to use Wokers
parent
e30962e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/tasks/orientdb.rake
+10
-23
10 additions, 23 deletions
lib/tasks/orientdb.rake
with
10 additions
and
23 deletions
lib/tasks/orientdb.rake
+
10
−
23
View file @
1989f622
...
...
@@ -11,9 +11,7 @@ namespace :orientdb do
task
create_learning_object_relations: :environment
do
desc
"Create LearningObject relations based on its metadata"
lo_repo
=
Portalmec
::
Application
.
repository
.
for
(
:learning_object
)
subject_repo
=
Portalmec
::
Application
.
repository
.
for
(
:subject
)
attr_repo
=
Portalmec
::
Application
.
repository
.
for
(
:attribute
)
include
RepositoriesProxy
# Quantity of LearningObjects fetched on each iteration
limit
=
1000
...
...
@@ -21,11 +19,11 @@ namespace :orientdb do
offset
=
0
loop
do
p
" --> importing LearningObjects from
#{
offset
}
to
#{
offset
+
limit
}
"
p
uts
" --> importing LearningObjects from
#{
offset
}
to
#{
offset
+
limit
}
"
begin
# Get LearningObjects from OrientDB (from offset to offset+limit)
learning_objects
=
l
o_repo
.
all_from_offset_to_limit
(
offset
,
limit
)
learning_objects
=
l
earning_object_repository
.
all_from_offset_to_limit
(
offset
,
limit
)
rescue
# Sleeps for a while to wait database's recovery
sleep
(
30
.
seconds
)
...
...
@@ -40,30 +38,19 @@ namespace :orientdb do
subjects
=
metadata
[
"dc.subject.category"
]
subjects
||=
[]
metadata
.
delete
(
"dc.subject.category"
)
lo
.
subjects
=
[]
lo
.
attributes
=
[]
subjects_array
=
[]
attributes_array
=
[]
subjects
.
each
do
|
subject_name
|
subject
=
subject_repo
.
find_by_name
(
subject_name
)
if
subject
.
nil?
subject
=
Subject
.
new
(
:name
=>
subject_name
)
subject_repo
.
create
(
subject
)
end
lo
.
subjects
<<
subject
subjects_array
<<
{
:name
=>
subject_name
}
end
metadata
.
each
do
|
key
,
value
|
value
.
each
do
|
v
|
attribute
=
attr_repo
.
find_by_key_and_value
(
key
,
v
).
first
if
attribute
.
nil?
attribute
=
Attribute
.
new
(
:key
=>
key
,
:value
=>
v
)
attr_repo
.
create
(
attribute
)
end
lo
.
attributes
<<
attribute
end
attributes_array
<<
{
:key
=>
key
,
:value
=>
value
}
end
lo_repo
.
c
reate
_r
elations
(
lo
)
C
reate
R
elations
Worker
.
perform_async
(
lo
.
id
,
subjects_array
,
attributes_array
)
end
offset
+=
limit
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment