igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

[bug] Do not store `scrape_interval_task` in `request.session` #104

Closed igorsimb closed 4 months ago

igorsimb commented 5 months ago

The logic should be: "If there is a scheduled task running for this user, do ..." and not "_If scrape_interval_task in the user's session, do ..._` Reason: if user logs out, the session breaking all the logic tied to it.

Steps to reproduce

  1. Create a schedule
  2. See "Delete existing" button
  3. Log out and log back in Expected result Nothings hould change

What actually happens "Delete existing" button disappears and there's a button "Create interval" as opposed to "Update interval".

igorsimb commented 5 months ago

in ItemListView's get_context_data

... 

try:
    existing_task = PeriodicTask.objects.get(name=f"scrape_interval_task_{self.request.user}")
except PeriodicTask.DoesNotExist:
    existing_task = None
sku = None
... 

context["existing_task"] = existing_task
return context

In template:

{% if existing_task %}
  TASK YES! :)
{% else %}
  TASK NO! :(
{% endif %}
igorsimb commented 5 months ago

For future reference, at least for now we should probably create a variable TASK_NAME instead of hard coding scrape_interval_task_{self.request.user} everywhere.