Skip to content

Commit

Permalink
Fix task initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
luabida committed Nov 8, 2022
1 parent 034cf1f commit 541ae73
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ downloads.db
*.gz

data/*

celerybeat-schedule.bak
celerybeat-schedule.dat
celerybeat-schedule.dir
4 changes: 2 additions & 2 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ channels:
- conda-forge
- defaults
dependencies:
- docker-compose #
- celery #
- docker-compose
- celery
- make
- poetry
- python=3.9
Expand Down
2 changes: 1 addition & 1 deletion docker/celery/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

exec celery -A satellite_weather_downloader.celery_app.celeryapp beat -l DEBUG
exec celery --workdir satellite_weather_downloader/celery_app --config celeryconfig -A tasks worker -B --loglevel=DEBUG
97 changes: 95 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MetPy = "^1.3.1"
SQLAlchemy = "^1.4.41"
python-dotenv = "^0.21.0"
psycopg2-binary = "^2.9.4"
netCDF4 = "^1.6.1"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down
5 changes: 5 additions & 0 deletions satellite_weather_downloader/celery_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celeryapp import app as celery_app

__all__ = ('celery_app',)
12 changes: 11 additions & 1 deletion satellite_weather_downloader/celery_app/celeryapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
app = Celery("satellite_weather_downloader")

app.config_from_object("satellite_weather_downloader.celery_app.celeryconfig")
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')


if __name__ == "__main__":
app.start()
worker = app.Worker(
include=['satellite_weather_downloader.celery_app.tasks']
)
worker.start()
6 changes: 4 additions & 2 deletions satellite_weather_downloader/celery_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os


from sqlalchemy import create_engine
from celery.schedules import crontab
from datetime import datetime, timedelta
Expand All @@ -18,8 +19,8 @@

PSQL_USER = os.getenv("POSTGRES_USER")
PSQL_PASSWORD = os.getenv("POSTGRES_PASSWORD")
HOST = os.getenv("PSQL_HOST")
PORT = os.getenv("PSQL_PORT")
HOST = os.getenv("POSTGRES_HOST")
PORT = os.getenv("POSTGRES_PORT")
DBASE = os.getenv("POSTGRES_DATABASE")


Expand Down Expand Up @@ -95,6 +96,7 @@ def reanalysis_fetch_data_daily():
for geocode in geocodes:
row = netcdf_to_dataframe(data, geocode)
cope_df = cope_df.merge(row, on=list(cope_df.columns), how='outer')
logging.info(f'{geocode} added to dataframe')

cope_df = cope_df.set_index('date')

Expand Down

0 comments on commit 541ae73

Please sign in to comment.