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
fd3bc886
Commit
fd3bc886
authored
5 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Added connection exception rescue to import task
parent
844d0859
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/import/learning_objects.rake
+37
-24
37 additions, 24 deletions
lib/tasks/import/learning_objects.rake
with
37 additions
and
24 deletions
lib/tasks/import/learning_objects.rake
+
37
−
24
View file @
fd3bc886
...
...
@@ -46,33 +46,46 @@ namespace :import do
n_items
=
0
loop
do
items
=
[]
uri
.
query
=
URI
.
encode_www_form
(
user_params
)
response
=
JSON
.
parse
(
Net
::
HTTP
.
get
(
uri
))
if
n_items
==
0
n_items
=
response
[
"response"
][
"numFound"
]
p
"
#{
n_items
}
items found"
end
begin
items
=
[]
uri
.
query
=
URI
.
encode_www_form
(
user_params
)
response
=
JSON
.
parse
(
Net
::
HTTP
.
get
(
uri
))
if
n_items
==
0
n_items
=
response
[
"response"
][
"numFound"
]
p
"
#{
n_items
}
items found"
end
break
if
params
[
:start
]
>
n_items
p
"--> importing items from
#{
params
[
:start
]
}
to
#{
params
[
:start
]
+
params
[
:rows
]
}
"
response
[
"response"
][
"docs"
].
each
do
|
doc
|
next
if
item_exists?
(
doc
[
"search.resourceid"
])
item
=
dspace_client
.
items
.
find
(
id:
doc
[
"search.resourceid"
],
expand:
"metadata,bitstreams,parentCollection"
)
if
items
.
is_a?
String
p
"Received a string instead of item:
#{
item
}
"
next
break
if
params
[
:start
]
>
n_items
p
"--> importing items from
#{
params
[
:start
]
}
to
#{
params
[
:start
]
+
params
[
:rows
]
}
"
response
[
"response"
][
"docs"
].
each
do
|
doc
|
next
if
item_exists?
(
doc
[
"search.resourceid"
])
item
=
dspace_client
.
items
.
find
(
id:
doc
[
"search.resourceid"
],
expand:
"metadata,bitstreams,parentCollection"
)
if
items
.
is_a?
String
p
"Received a string instead of item:
#{
item
}
"
next
end
items
<<
item
end
items
<<
item
p
"
#{
items
.
count
}
items retrieved"
importer
=
Dspace
::
LearningObjectImporter
.
new
(
items
,
user
,
dspace_client
)
importer
.
import
rescue
PG
::
ConnectionBad
,
Faraday
::
TimeoutError
,
Net
::
HTTP
::
Persistent
::
Error
,
Net
::
ReadTimeout
=>
e
p
"Database error, going to sleep"
p
e
p
e
.
class
p
e
.
message
ActiveRecord
::
Base
.
clear_active_connections!
# Sleeps for a while to wait database's recovery
sleep
(
60
.
seconds
)
# Goes to next iteration to retry
next
else
params
[
:start
]
+=
params
[
:rows
]
end
params
[
:start
]
+=
params
[
:rows
]
p
"
#{
items
.
count
}
items retrieved"
importer
=
Dspace
::
LearningObjectImporter
.
new
(
items
,
user
,
dspace_client
)
importer
.
import
end
end
end
...
...
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