lilspikey/django-background-task — Issue #3: Tasks not added to _tasks[] queue for some reason?
Author: givity
Created: 2011-12-30 10:36:07+00:00
State: open

I setup a rather-simple function to be queued with your lovely decorator and after executing the function, the task is in queue but receives an error message coming from your very own tasks.py. Note that I'm running manage.py process_tasks in a separate terminal on my Windows 7 dev box; I keep coming up with the following error:

Traceback (most recent call last):
File "C:\Users\givity\Envs\givity\lib\site-packages\background_task\tasks.py", line 162, in run_task
tasks.run_task(task.task_name, args, kwargs)
File "C:\Users\givity\Envs\givity\lib\site-packages\background_task\tasks.py", line 46, in run_task
task = self._tasks[task_name]
KeyError: u'projects.lib.files.files_chop'
WARNING:root:Rescheduling task Task(projects.lib.files.files_chop) for 0:00:21 later at 2011-12-30 04:28:00.596000
> c:\users\givity\envs\givity\lib\site-packages\background_task\tasks.py(46)run_task()

I through in a pdb.set_trace() right above line 44 ("task = self._tasks[task_name]") to see if I could grasp what was going on:

-> task = self._tasks[task_name]
(Pdb) self._tasks
{}

Notice that self._tasks is consistently empty.

My code for the actual tasks is as follows:

```python
@background(schedule=60)
def files_chop(path):
""" chop away div elements with class givity-chop
"""
# change the current working dir to the new project folder
os.chdir(path)
logger.info('changed folder to %s' % path)

# remove all class="givity-chop" divs, etc.
files = find_files(path, search_pattern='*.html')
logger.info('files found: %s' % files)
...
```

Of course, I'm calling the function files_chop(path) elsewhere:

```python
files_chop(project_path_src)
```