Skip to content

Commit

Permalink
bring django-rq back
Browse files Browse the repository at this point in the history
  • Loading branch information
po5i committed Jun 7, 2018
1 parent b015e24 commit 1383a74
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
url='https://github.com/takeflight/wagtail-linkchecker',

install_requires=[
'django-rq>=1.1.0',
'wagtail>=1.0',
'requests>=2.9.1',
'celery>=4.0,<4.1'
],
zip_safe=False,
license='BSD License',
Expand Down
36 changes: 1 addition & 35 deletions wagtaillinkchecker/management/commands/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,4 @@ def handle(self, *args, **kwargs):
print(f'Scanning {len(pages)} pages...')
scan = broken_link_scan(site)
broken_links = ScanLink.objects.filter(scan=scan, crawled=True)
print(f'Found {len(broken_links)} broken links.')

messages = []
for page in pages:
revisions = PageRevision.objects.filter(page=page)
user = None
user_email = settings.DEFAULT_FROM_EMAIL
if revisions:
revision = revisions.latest('created_at')
user = revision.user
user_email = revision.user.email if revision.user else ''
page_broken_links = []
for link in broken_links:
if link.page == page:
page_broken_links.append(link)
email_message = render_to_string(
'wagtaillinkchecker/emails/broken_links.html', {
'page_broken_links': page_broken_links,
'user': user,
'page': page,
'base_url': site.root_url,
'site_name': settings.WAGTAIL_SITE_NAME,
})
email = EmailMessage(
'Broken links on page "%s"' % (page.title),
email_message,
settings.DEFAULT_FROM_EMAIL,
[user_email])
email.content_subtype = 'html'
messages.append(email)

connection = mail.get_connection()
connection.open()
connection.send_messages(messages)
connection.close()
print('Links enqueued on Redis')
8 changes: 6 additions & 2 deletions wagtaillinkchecker/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import django_rq

from django.conf import settings
from django.db import models
from django.db.models.signals import pre_delete
Expand Down Expand Up @@ -105,8 +107,10 @@ def page_is_deleted(self):

def check_link(self):
from wagtaillinkchecker.tasks import check_link
check_link(self.pk)

queue_name = getattr(settings, 'RQ_DEFAULT_QUEUE', 'default')
queue = django_rq.get_queue(
queue_name, autocommit=True, async=True, default_timeout=360)
queue.enqueue(check_link, self.pk)

@receiver(pre_delete, sender=Page)
def delete_tag(instance, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions wagtaillinkchecker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ def check_link(link_pk):
scan = link.scan
scan.scan_finished = timezone.now()
scan.save()

return True

0 comments on commit 1383a74

Please sign in to comment.