import os
import time

import rethinkdb as r
import requests

from krunchr.vendors.celery import celery, db


@celery.task(bind=True)
def get_file(self, url, path):
  name, ext = os.path.splitext(url)
  name = str(int(time.time()))

  path = "%s/%s%s" % (path, name, ext)

  response = requests.get(url)
  with open(path, 'w') as f:
    f.write(response.content)

  r.table('jobs').filter({
      'task_id': self.request.id
  }).update({'state': 'done'}).run(db)

import os
import time

import requests

from krunchr.vendors.celery import celery


@celery.task
def get_file(url, path):
  name, ext = os.path.splitext(url)
  name = str(int(time.time()))

  path = "%s/%s%s" % (path, name, ext)

  response = requests.get(url)
  print path
  with open(path, 'w') as f:
    f.write(response.content)

--- 
+++ 
@@ -1,19 +1,23 @@
 import os
 import time
 
+import rethinkdb as r
 import requests
 
-from krunchr.vendors.celery import celery
+from krunchr.vendors.celery import celery, db
 
 
-@celery.task
-def get_file(url, path):
+@celery.task(bind=True)
+def get_file(self, url, path):
   name, ext = os.path.splitext(url)
   name = str(int(time.time()))
 
   path = "%s/%s%s" % (path, name, ext)
 
   response = requests.get(url)
-  print path
   with open(path, 'w') as f:
     f.write(response.content)
+
+  r.table('jobs').filter({
+      'task_id': self.request.id
+  }).update({'state': 'done'}).run(db)
Update job state when we finish the task
