React - Flask - RQ - Scrapy - MongoDB Pipeline Integration and Debug#28
React - Flask - RQ - Scrapy - MongoDB Pipeline Integration and Debug#28Miclin1024 wants to merge 21 commits into
Conversation
|
The workflow is functioning properly now. I'm able to use the UI to submit a job request through the API, have Flask process the request and send it to RQ whose worker will pick up the job and run Scrapy, and confirm that Scrapy will actually sync the job status and scraped data with the MongoDB instance. I had to disable sign in due to some lingering issues with the authentication setup, but I think it would be a good idea to merge this branch first @jhaber-zz. |
| @@ -0,0 +1 @@ | |||
| from .run_spider import scrapy_execute | |||
There was a problem hiding this comment.
In this new setup, the Scrapy project becomes a sub-package under server. A driver function scrape_execute in run_spider.py was added to serve as an entry point for rq.
| # https://docs.scrapy.org/en/latest/topics/spider-middleware.html | ||
| import os | ||
|
|
||
| from scrapy.utils.project import get_project_settings |
There was a problem hiding this comment.
scrapy.settings was integrated into server.settings. Reference to google api token was removed for security. It is now in a .env file that's source controlled. A template file for .env was added in #29.
| @@ -0,0 +1,43 @@ | |||
| const path = require("path"); | |||
There was a problem hiding this comment.
The new CI setup using webpack and babel. This is being used in package.json's npm scripts. An update to our current README is needed.
| @@ -1,123 +0,0 @@ | |||
| from pymongo.results import UpdateResult | |||
There was a problem hiding this comment.
Renamed to tracking.py
| @@ -1,51 +0,0 @@ | |||
| { | |||
There was a problem hiding this comment.
Moved npm packages to project root.
| @@ -1,372 +0,0 @@ | |||
| import React, {Component} from "react"; | |||
There was a problem hiding this comment.
Renamed to JobsDashboard.js to better distinguish it from Job.js.
| @@ -0,0 +1,43 @@ | |||
| module.exports = { | |||
There was a problem hiding this comment.
ESLint for enforcing coding style.
| import AutorenewIcon from '@material-ui/icons/Autorenew'; | ||
| import Box from '@material-ui/core/Box'; | ||
| import Paper from '@material-ui/core/Paper'; | ||
| import { |
There was a problem hiding this comment.
These new import statements are for migrating to material-ui v5 and react-router-dom v6.
In terms of actual code change, for mui most of the updates were due to the deprecation of makeStyle, and for react-router-dom it was the removal of the history state. This part was quite significant because of the extensive use of both APIs in our code.
| @@ -0,0 +1,30 @@ | |||
| import os | |||
There was a problem hiding this comment.
For modularity the Flask backend is restructured using package and blueprints.
| app.config.from_mapping(test_config) | ||
|
|
||
| from .home import views as home_views | ||
| app.register_blueprint(home_views.bp) |
There was a problem hiding this comment.
home/views.py serves various entry points to React. It renders an HTML template along with the javascript bundle from babel/webpack.
| from .jobs import interfaces as job_interfaces | ||
| app.register_blueprint(job_interfaces.bp) | ||
| from .jobs import actions as job_actions | ||
| app.register_blueprint(job_actions.bp) |
There was a problem hiding this comment.
jobs/interfaces.py and jobs/actions.py serve the APIs interacting with the job dispatcher and tracker.
| <title>Crawl4All: A Universal Web Crawling App</title> | ||
| </head> | ||
| <body> | ||
| <div id="react-app"></div> |
There was a problem hiding this comment.
All React content will be rendered inside this <div> box.
| def decorator(*args, **kwargs): | ||
| token = None | ||
| if DEBUG_NO_AUTH_ENABLED: | ||
| g.user = "NO_AUTH_ENABLED" |
There was a problem hiding this comment.
The temporary backdoor to bypass user authentication until it is fixed.
|
|
||
| @bp.before_request | ||
| @token_required | ||
| def before_request(): |
There was a problem hiding this comment.
Require auth for all APIs in this blueprint
| @validate_job_id | ||
| def before_request(): | ||
| """Validate user and job_id at all action endpoints.""" | ||
| pass |
There was a problem hiding this comment.
Validate all job_id prior to all requests to server.actions and standardize error handling.
No description provided.