Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
a5038856
Commit
a5038856
authored
4 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
after import is successfully performed create rename file to backup file name
parent
ff59a5d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!231
Resolve "auto-import of subject data"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/importer/importer_cron_job.py
+18
-10
18 additions, 10 deletions
smash/web/importer/importer_cron_job.py
with
18 additions
and
10 deletions
smash/web/importer/importer_cron_job.py
+
18
−
10
View file @
a5038856
# coding=utf-8
import
datetime
import
logging
import
os
import
os.path
import
traceback
...
...
@@ -22,8 +24,8 @@ class ImporterCronJob(CronJobBase):
@timeout_decorator.timeout
(
CRON_JOB_TIMEOUT
)
def
do
(
self
):
title
=
"
Daily import
"
recipients
=
getattr
(
settings
,
"
DEFAULT_FROM_EMAIL
"
,
None
)
email_
title
=
"
Daily import
"
email_
recipients
=
getattr
(
settings
,
"
DEFAULT_FROM_EMAIL
"
,
None
)
filename
=
getattr
(
settings
,
"
DAILY_IMPORT_FILE
"
,
None
)
...
...
@@ -32,22 +34,28 @@ class ImporterCronJob(CronJobBase):
return
"
import file not defined
"
logger
.
info
(
"
Importing subjects from file:
"
+
filename
)
if
not
os
.
path
.
isfile
(
filename
):
EmailSender
().
send_email
(
title
,
EmailSender
().
send_email
(
email_
title
,
"
<h3><font color=
'
red
'
>File with imported data is not available in the system:
"
+
filename
+
"
</font></h3>
"
,
recipients
)
email_
recipients
)
return
"
import file not found
"
try
:
importer
=
Importer
(
settings
.
DAILY_IMPORT_FILE
,
CsvSubjectImportReader
())
importer
.
execute
()
body
=
importer
.
get_summary
()
EmailSender
().
send_email
(
title
,
"
<h3>Data was successfully imported from file:
"
+
filename
+
"
</h3>
"
+
body
,
recipients
)
email_body
=
importer
.
get_summary
()
EmailSender
().
send_email
(
email_title
,
"
<h3>Data was successfully imported from file:
"
+
filename
+
"
</h3>
"
+
email_body
,
email_recipients
)
self
.
backup_file
(
filename
)
return
"
import is successful
"
except
:
tb
=
traceback
.
format_exc
()
EmailSender
().
send_email
(
title
,
EmailSender
().
send_email
(
email_
title
,
"
<h3><font color=
'
red
'
>There was a problem with importing data from file:
"
+
filename
+
"
</font></h3><pre>
"
+
tb
+
"
</pre>
"
,
recipients
)
email_
recipients
)
return
"
import crashed
"
def
backup_file
(
self
,
filename
):
new_file
=
filename
+
"
-
"
+
datetime
.
datetime
.
now
().
strftime
(
"
%Y-%m-%d-%H-%M
"
)
+
"
.bac
"
os
.
rename
(
filename
,
new_file
)
return
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