forked from BitCurator/bitcurator-access-webtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcaw_celery_task.py
60 lines (53 loc) · 2.14 KB
/
bcaw_celery_task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# coding=UTF-8
#
# BitCurator Access Webtools (Disk Image Access for the Web)
# Copyright (C) 2014
# All rights reserved.
#
# This code is distributed under the terms of the GNU General Public
# License, Version 3. See the text file "COPYING" for further details
# about the terms of this license.
#
# This file contains celery support code for the BitCurator Access Webtools application.
#
from flask import Flask, current_app
from bcaw import app
from celery import Celery
import bcaw
from bcaw import *
# FIXME: The following are already defined in bcaw_default_Settings.py.
# Need to figure out how to include that file here so the following 2 lines
# can be removed.
app.config['CELERY_BROKER_URL'] = 'amqp://guest@localhost//'
app.config['CELERY_RESULT_BACKEND'] = 'amqp://guest@localhost//'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
@celery.task
def bcawIndexAsynchronously():
""" This is the Celery worker task which is run in parallel with the
bcaw app. When user chooses to generate Lucene indexes for the disk
images, the mail app (bcaw) calls this worker thread which in turn,
invokes the indexing routine.
This task is invoked by the following command:
$ celery -A bcaw_celery_task.celery worker --loglevel=INFO
"""
""" Background task to index the files """
with app.app_context():
# print "Calling bcawIndexAllFiles..."
# print "Current app: ", current_app.name
bcaw.image_browse.bcawIndexAllFiles()
@celery.task
def bcawBuildDfxmlTableAsynchronously():
""" Background task to build dfxml table """
with app.app_context():
# print "Calling dbBuildDb for DFXML..."
# print "Current app: ", current_app.name
bcaw.bcaw_db.dbBuildDb(bld_imgdb = False, bld_dfxmldb = True)
@celery.task
def bcawBuildAllTablesAsynchronously():
""" Background task to build image and dfxml table """
with app.app_context():
# print "Calling dbBuildDb for DFXML..."
# print "Current app: ", current_app.name
bcaw.bcaw_db.dbBuildDb(bld_imgdb = True, bld_dfxmldb = True)