Skip to content

React - Flask - RQ - Scrapy - MongoDB Pipeline Integration and Debug#28

Open
Miclin1024 wants to merge 21 commits into
mainfrom
flask-cors-fix
Open

React - Flask - RQ - Scrapy - MongoDB Pipeline Integration and Debug#28
Miclin1024 wants to merge 21 commits into
mainfrom
flask-cors-fix

Conversation

@Miclin1024

Copy link
Copy Markdown
Contributor

No description provided.

@Miclin1024 Miclin1024 requested a review from jhaber-zz March 9, 2022 19:28
@Miclin1024 Miclin1024 requested a review from hwarnuh April 7, 2022 05:31
@Miclin1024 Miclin1024 changed the title [WIP] Package update, NodeJS removal, and workflow refactoring Scrapy, Flask, React intergration and workflow debugging Apr 7, 2022
@Miclin1024 Miclin1024 changed the title Scrapy, Flask, React intergration and workflow debugging React - Flask - RQ - Scrapy - MongoDB Pipeline Integration and Debug Apr 7, 2022
@Miclin1024

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread server/settings.py
# https://docs.scrapy.org/en/latest/topics/spider-middleware.html
import os

from scrapy.utils.project import get_project_settings

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread webpack.common.js
@@ -0,0 +1,43 @@
const path = require("path");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to tracking.py

Comment thread client/package.json
@@ -1,51 +0,0 @@
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved npm packages to project root.

Comment thread client/src/pages/Jobs.js
@@ -1,372 +0,0 @@
import React, {Component} from "react";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to JobsDashboard.js to better distinguish it from Job.js.

Comment thread .eslintrc.js
@@ -0,0 +1,43 @@
module.exports = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread server/__init__.py
@@ -0,0 +1,30 @@
import os

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For modularity the Flask backend is restructured using package and blueprints.

Comment thread server/__init__.py
app.config.from_mapping(test_config)

from .home import views as home_views
app.register_blueprint(home_views.bp)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

home/views.py serves various entry points to React. It renders an HTML template along with the javascript bundle from babel/webpack.

Comment thread server/__init__.py
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All React content will be rendered inside this <div> box.

Comment thread server/jobs/utils.py
def decorator(*args, **kwargs):
token = None
if DEBUG_NO_AUTH_ENABLED:
g.user = "NO_AUTH_ENABLED"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary backdoor to bypass user authentication until it is fixed.

Comment thread server/jobs/interfaces.py

@bp.before_request
@token_required
def before_request():

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require auth for all APIs in this blueprint

Comment thread server/jobs/actions.py
@validate_job_id
def before_request():
"""Validate user and job_id at all action endpoints."""
pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate all job_id prior to all requests to server.actions and standardize error handling.

@Miclin1024 Miclin1024 requested a review from ThaiHipster April 13, 2022 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant