Commit b7f93075 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add cron for menage

parent f77cb0e8
......@@ -2,3 +2,5 @@
.idea
srv/database.sqlite
application.properties
logs/*
!logs/README
#!/usr/bin/env python3
from lib.crons import Crons
crons = Crons()
crons.clear() # Useless but can be useful if the code change in Crons code
../lib
\ No newline at end of file
import getpass
from crontab import CronTab
class Crons:
def __init__(self, base_dir=None):
self.base_dir = base_dir
self.my_cron = CronTab(user=getpass.getuser())
self.clear()
def clear(self):
# Remove old crons:
self.my_cron.remove_all(comment="dgenies")
self.my_cron.write()
def init_menage_cron(self):
"""
Menage cron is launched at 1h00am each day
"""
if self.base_dir is not None:
job = self.my_cron.new("python3 {0}/bin/clean_jobs.py > {0}/logs/menage.log".format(self.base_dir),
comment="dgenies")
job.day.every(1)
job.hour.on(1)
job.minute.on(0)
self.my_cron.write()
else:
raise Exception("Crons: base_dir must not be None")
This folder will contains some logs from dgenies server.
......@@ -7,3 +7,4 @@ numpy
wget==3.2
requests==2.18.*
biopython==1.70
python-crontab==2.2.*
../logs
\ No newline at end of file
......@@ -15,6 +15,7 @@ from lib.functions import Functions, ALLOWED_EXTENSIONS
from lib.upload_file import UploadFile
from lib.Fasta import Fasta
from lib.mailer import Mailer
from lib.crons import Crons
import sys
......@@ -44,6 +45,10 @@ mailer = Mailer(app)
# Folder containing data:
app_data = config_reader.get_app_data()
# Crons:
crons = Crons(app_folder)
crons.init_menage_cron()
@app.context_processor
def get_launched_results():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment