mitmedialab / django-channels-presence

"Rooms" and "Presence" for django-channels
MIT License
79 stars 38 forks source link

Unknown command: 'prune_presence' #11

Closed luskbo closed 6 years ago

luskbo commented 6 years ago

After installing and configuring the plugin, it seems to have no problem adding values to the channels_presence_room and channels_presence_presence tables.

Also, setup a javascript to send a heartbeat. This works, and updates the timestamp in the channels_presence_presence.

The problem is that the pruning doesn't seem to work. I have setup the celery task, but i'm not sure it is ever being called as the values are never pruned from the DB.

I do use celery for many other tasks, so I know that my celery install is fine.

Also, I activated the enviroment and attempted to run ./manage.py prune_presence

This command fails. Unknown command: 'prune_presence'

This command works: ./manage.py prune_rooms

but returns no results, and doesn't remove the room from the DB.

Also, one thing I just noticed is that the channel_name shows up as daphne.response.AVmlqaOxtA!xfruPXOqRj

Not sure if that is expected.

yourcelf commented 6 years ago

Do you have "channels_presence" listed in INSTALLED_APPS in settings.py? The management command not showing up sounds like a symptom of that.

luskbo commented 6 years ago

I do. Also, this command doesn't error:

This command works: ./manage.py prune_rooms

It just doesn't do anything.

Do you know what values are supposed to be pushed into channels_presence_presence table ?

Is this what I should expect to populate into the channel_name field of the table? channel_name
daphne.response.KHuOGxrzrv!crPawQQxvK

The @touch_presence decorator does work and updated the timestamp in that table. All seem to work, except for the pruning.

yourcelf commented 6 years ago

Ah, it's a docs problem; the management command is prune_presences (plural).

The channel_name field in Presence is populated with the connection's reply channel name, which is autogenerated by channels. The value you listed looks right; though the details are up to channels and might change.

luskbo commented 6 years ago

That explains why it wasn't working via manag. I think I may have found out why it is not working via celery schedule or automatically though.

When running it manually via manag, I get this error:

./manage.py prune_presences
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/opt/testsite/venv/lib/python3.5/site-packages/channels_presence/management/commands/prune_presences.py", line 6, in handle
    Room.objects.prune_presences()
  File "/opt/testsite/venv/lib/python3.5/site-packages/channels_presence/models.py", line 56, in prune_presences
    room.prune_presences(age)
  File "/opt/testsite/venv/lib/python3.5/site-packages/channels_presence/models.py", line 105, in prune_presences
    last_seen__lt=now() - timedelta(seconds=age_in_seconds)
TypeError: unsupported type for timedelta seconds component: str

My settings.py looks like this:


    'prune-presence': {
        'task': 'channels_presence.tasks.prune_presence',
        'schedule': timedelta(seconds=60)
    },
    'prune-rooms': {
        'task': 'channels_presence.tasks.prune_rooms',
        'schedule': timedelta(seconds=60)
    }
}```

Tried adding single and double quotes and get a similar but different error at this point.

``` ./manage.py prune_presences
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 308, in execute
    settings.INSTALLED_APPS
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/testsite/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/opt/testsite/testsite/testsite/settings.py", line 188, in <module>
    'schedule': timedelta(seconds="60")
TypeError: unsupported type for timedelta seconds component: str```
luskbo commented 6 years ago

Okay. Got it to work. It was the quotes around the Max Age var in settings:

CHANNELS_PRESENCE_MAX_AGE = "120" to CHANNELS_PRESENCE_MAX_AGE = 120

Thanks for the help troubleshooting! Will give you a heads you if I notice any issues!