Skip to content

Commit

Permalink
Compatible with the latest arq usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dongweiming committed Aug 27, 2021
1 parent 38f41cf commit 9792c46
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lyanna

[![Build Status](https://travis-ci.org/dongweiming/lyanna.svg?branch=master)](https://travis-ci.org/dongweiming/lyanna)
[![Build Status](https://app.travis-ci.com/dongweiming/lyanna.svg?branch=master)](https://app.travis-ci.com/github/dongweiming/lyanna)
![Tag](https://img.shields.io/github/v/tag/dongweiming/lyanna)
![Python Version](https://img.shields.io/badge/python-3.8-blue)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
Expand Down
8 changes: 4 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ async def _migrate_for_v30() -> None:


async def _migrate_for_v35() -> None:
await init_db(create_db=False)
client = Tortoise.get_connection('default')
await client.execute_script(
'alter table activity add index `idx_target_kind` (`target_id`, `target_kind`)') # noqa
await init_db(create_db=False)
client = Tortoise.get_connection('default')
await client.execute_script(
'alter table activity add index `idx_target_kind` (`target_id`, `target_kind`)') # noqa


@click.group()
Expand Down
2 changes: 1 addition & 1 deletion models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def from_url(cls, db_url: str) -> RedisSettings:
url = _parse_rfc1738_args(db_url)
return cls(url['host'], url['port'],
url['database'] and int(url['database']) or 0,
url['password'], 1, 5, 1)
url['password'], None, 5, 1)


async def get_redis(loop=None) -> Redis:
Expand Down
11 changes: 6 additions & 5 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import aiosmtplib
from arq import create_pool, cron
from arq.worker import logger
from mako.lookup import TemplateLookup
from tortoise.query_utils import Q

from config import (BLOG_URL, MAIL_PASSWORD, MAIL_PORT, MAIL_SERVER,
MAIL_USERNAME, REDIS_URL, SITE_TITLE)
Expand Down Expand Up @@ -64,7 +64,7 @@ async def mention_users(ctx, post_id, content, author_id):
html = template.render(username=user.username,
site_url=BLOG_URL, post=post,
site_name=SITE_TITLE)
print(f'Send Mail(subject={subject}, html={html}) To {email}')
logger.info(f'Send Mail(subject={subject}, html={html}) To {email}')
await send_email(subject, html.decode(), email)


Expand All @@ -75,15 +75,16 @@ async def flush_to_db(ctx):
if (post_id := await redis.spop(RK_VISITED_POST_IDS)) is None:
break

post = await Post.get(Q(id=post_id))
post = await Post.filter(id=post_id).first()
if post:
post._pageview = int(await redis.hget(
RK_PAGEVIEW.format(post_id), PAGEVIEW_FIELD) or 0)
await post.save()
print(f'Flush Post(id={post_id}) pageview')
logger.info(f'Flush Post(id={post_id}) pageview')
else:
logger.warning(f'Post(id={post_id}) have deleted!')


class WorkerSettings:
functions = [mention_users]
redis_settings = RedisSettings.from_url(REDIS_URL)
cron_jobs = [cron(flush_to_db, hour=None)]
4 changes: 2 additions & 2 deletions views/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ async def tag(request, tag_id):
@bp.route('/topics')
@bp.route('/topics/<ident>')
@mako.template('topics.html')
async def topics(request: Request, ident: str = 1) -> Dict[str, Pagination]:
async def topics(request: Request, ident_: str = "1") -> Dict[str, Pagination]:
try:
ident = int(ident)
ident = int(ident_)
except ValueError:
abort(404)
start = (ident - 1) * PER_PAGE
Expand Down

0 comments on commit 9792c46

Please sign in to comment.