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)

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)

Update job state when we finish the task
Update job state when we finish the task

  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
+ @celery.task(bind=True)
- def get_file(url, path):
+ 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
## Code Before:
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)

## Instruction:
Update job state when we finish the task
## Code After:
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)
