Fix day filter
[cds-indico.git] / indico / util / tasks.py
blobc1871cdfb87e584d85ec148d4f3b2d11affe48f9
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 """
18 This module contains very generic Celery tasks which are not specific
19 to any other module. Please add tasks in here only if they are generic
20 enough to be possibly useful somewhere else. If you need to import
21 anything from `indico.modules`, your task most likely does not belong
22 in here but in your module instead.
23 """
25 from __future__ import unicode_literals
27 import os
29 from indico.core.celery import celery
30 from indico.core.logger import Logger
31 from indico.util.fs import silentremove
34 @celery.task(name='delete_file')
35 def delete_file(path):
36 """Deletes a file.
38 This task is meant to be invoked with a delay, i.e. like this::
40 delete_file.apply_async(args=[file_path], countdown=3600)
42 :param path: The absolute path to the file.
43 """
44 if not os.path.isabs(path):
45 raise ValueError('Path is not absolute: {}'.format(path))
46 Logger.get().info('Deleting {}'.format(path))
47 silentremove(path)