-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks.py
More file actions
63 lines (51 loc) · 1.63 KB
/
Copy pathtasks.py
File metadata and controls
63 lines (51 loc) · 1.63 KB
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
61
62
63
"""Celery tasks for tower app."""
from flask import Flask
from mongoengine import connect
from config import config
from celery import Celery
import datetime
"""Celery application code."""
import os
if os.path.exists('.env'):
for line in open('.env'):
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
# Make the database connection:
# Set the config settings to whatever the app is using.
this_config = os.getenv('FLASK_CONFIG') or 'default'
app = Flask(__name__)
app.config.from_object(config[this_config])
config[this_config].init_app(app)
host = config[this_config]().MONGODB_SETTINGS['HOST']
connect(
db='pulsepod-restore',
host=host
)
from app.models import Metadata, DropboxFiles
# Make the database connection:
# connect(host=this_config().mongo_url())
find_files = DropboxFiles.find_files
celery = Celery('mpala_tower')
celery.config_from_object("celery_settings")
def doy(date=None):
"""Return a DOY from a datetime object."""
if not date:
date = datetime.datetime.now()
this_ordinal = date.toordinal()
year_ordinal = datetime.datetime(date.year, 1, 1).toordinal()
return this_ordinal - year_ordinal + 1
@celery.task(bind=True)
def create_metadata_task(self, year, doy):
"""Celery task to create metadata."""
# Import the ORM for the metadata
self.update_state(state='PROGESS')
Metadata(
year=year,
doy=doy,
files=find_files(year=year, doy=doy)
).generate_metadata()
@celery.task(bind=True)
def process_smap_data(self):
"""Update SMAP data and upload to FTP server."""
self.update_state(state='PROGRESS')