from celery import Celery
import requests

from .config import get_engine, _set_connection_string
from .loader import FDPLoader

app = Celery('fdp_loader')
app.config_from_object('babbage_fiscal.celeryconfig')

@app.task
def load_fdp_task(package, callback, connection_string=None):
    if connection_string is not None:
        _set_connection_string(connection_string)
    FDPLoader.load_fdp_to_db(package, get_engine())
    ret = requests.get(callback)

from celery import Celery
import requests

from .config import get_engine, _set_connection_string
from .loader import FDPLoader

app = Celery('fdp_loader')
app.config_from_object('babbage_fiscal.celeryconfig')

@app.task
def load_fdp_task(package, callback, connection_string=None):
    if connection_string is not None:
        _set_connection_string(connection_string)
    try:
        FDPLoader.load_fdp_to_db(package, get_engine())
        requests.get(callback, params={'package': package, 'status': 'done'})
    except Exception as e:
        requests.get(callback, params={'package': package, 'status': 'fail', 'error': str(e)})

Add more info to the callback
Add more info to the callback

  from celery import Celery
  import requests
  
  from .config import get_engine, _set_connection_string
  from .loader import FDPLoader
  
  app = Celery('fdp_loader')
  app.config_from_object('babbage_fiscal.celeryconfig')
  
  @app.task
  def load_fdp_task(package, callback, connection_string=None):
      if connection_string is not None:
          _set_connection_string(connection_string)
+     try:
-     FDPLoader.load_fdp_to_db(package, get_engine())
+         FDPLoader.load_fdp_to_db(package, get_engine())
-     ret = requests.get(callback)
+         requests.get(callback, params={'package': package, 'status': 'done'})
+     except Exception as e:
+         requests.get(callback, params={'package': package, 'status': 'fail', 'error': str(e)})
  
Add more info to the callback
## Code Before:
from celery import Celery
import requests

from .config import get_engine, _set_connection_string
from .loader import FDPLoader

app = Celery('fdp_loader')
app.config_from_object('babbage_fiscal.celeryconfig')

@app.task
def load_fdp_task(package, callback, connection_string=None):
    if connection_string is not None:
        _set_connection_string(connection_string)
    FDPLoader.load_fdp_to_db(package, get_engine())
    ret = requests.get(callback)

## Instruction:
Add more info to the callback
## Code After:
from celery import Celery
import requests

from .config import get_engine, _set_connection_string
from .loader import FDPLoader

app = Celery('fdp_loader')
app.config_from_object('babbage_fiscal.celeryconfig')

@app.task
def load_fdp_task(package, callback, connection_string=None):
    if connection_string is not None:
        _set_connection_string(connection_string)
    try:
        FDPLoader.load_fdp_to_db(package, get_engine())
        requests.get(callback, params={'package': package, 'status': 'done'})
    except Exception as e:
        requests.get(callback, params={'package': package, 'status': 'fail', 'error': str(e)})
