-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f3a2b4
commit 59bc439
Showing
9 changed files
with
84 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import asyncio | ||
|
||
from aiohttp import ClientSession | ||
from arq import create_pool | ||
from arq.connections import RedisSettings | ||
|
||
from articlesa.config import RedisConfig | ||
from articlesa.logger import logger | ||
from articlesa.worker.parse import parse_article | ||
|
||
|
||
async def make_pool(): | ||
"""Create a redis pool for the worker, used to enqueue jobs.""" | ||
return await create_pool( | ||
RedisSettings( | ||
host=RedisConfig.host, | ||
port=RedisConfig.port, | ||
) | ||
) | ||
|
||
|
||
async def startup(ctx): | ||
"""Startup function for arq worker, creates aiohttp session.""" | ||
logger.info("starting up") | ||
ctx['session'] = await ClientSession().__aenter__() | ||
|
||
|
||
async def shutdown(ctx): | ||
"""Shutdown function for arq worker, closes aiohttp session.""" | ||
logger.info("shutting down") | ||
await ctx['session'].__aexit__(None, None, None) | ||
|
||
|
||
class WorkerSettings: | ||
"""https://arq-docs.helpmanual.io/#arq.worker.Worker""" | ||
functions = [parse_article] | ||
on_startup = startup | ||
on_shutdown = shutdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
|
||
from arq import create_pool | ||
from arq.connections import RedisSettings | ||
|
||
|
||
async def main(): | ||
redis = await create_pool(RedisSettings()) | ||
for url in ('https://facebook.com', 'https://microsoft.com', 'https://github.com'): | ||
await redis.enqueue_job('parse_article', url) | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ google.com | |
twitter.com | ||
t.co | ||
linkedin.com | ||
amazon.com | ||
amazon.com | ||
archive.org |