Skip to content

Commit

Permalink
fix golang app with dump, clear redis&fw
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Apr 5, 2023
1 parent c60088a commit e740af4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release_apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ macos-latest, ubuntu-22.04, windows-latest ]
platform: [ macos-latest, ubuntu-20.04, windows-latest ]

runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -30,7 +30,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
Expand Down
20 changes: 11 additions & 9 deletions yyetsweb/common/dump_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def prepare_mysql():
aliasname varchar(256) null,
area varchar(32),
views int null,
data longtext null
data longtext null,
douban longtext null,
image blob null
) charset utf8mb4;
"""
comment_sql = """
Expand Down Expand Up @@ -143,7 +145,9 @@ def prepare_sqlite():
aliasname varchar(256) null,
area varchar(32),
views int null,
data longtext null
data longtext null,
douban longtext null,
image blob null
);
"""
comment_sql = """
Expand Down Expand Up @@ -174,11 +178,12 @@ def dump_resource():
for each in tqdm(res, total=db["yyets"].count_documents({})):
line = list(each.values())
line[-1] = json.dumps(line[-1], ensure_ascii=False)
line.extend(["", ""])
batch_data.append(line)
mb.append(each)
if len(batch_data) == CHUNK_SIZE:
sql1 = "insert into yyets values (%s, %s, %s, %s, %s, %s, %s)"
sql2 = "insert into yyets values (?, ?, ?, ?, ?,?,?)"
sql1 = "insert into yyets values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
sql2 = "insert into yyets values (?, ?, ?, ?, ?,?,?,?,?)"
insert_func(batch_data, mb, sql1, sql2, "yyets")
batch_data = []
mb = []
Expand Down Expand Up @@ -225,18 +230,15 @@ def zip_file():
zf.write(sqlite_file, "yyets_sqlite.db")

logging.info("Dumping MySQL...")
subprocess.check_output(
"mysqldump -h mysql -u root -proot zimuzu > zimuzu.sql", shell=True
)
subprocess.check_output("mysqldump -h mysql -u root -proot zimuzu > zimuzu.sql", shell=True)
p = data_path.joinpath("yyets_mysql.zip")
logging.info("Zipping MySQL...")
with zipfile.ZipFile(p, "w", zipfile.ZIP_DEFLATED) as zf:
zf.write("zimuzu.sql")

logging.info("Dumping MongoDB")
subprocess.check_output(
"mongodump -h mongo -d share --gzip --archive="
+ data_path.joinpath("yyets_mongo.gz").as_posix(),
"mongodump -h mongo -d share --gzip --archive=" + data_path.joinpath("yyets_mongo.gz").as_posix(),
shell=True,
)

Expand Down
2 changes: 2 additions & 0 deletions yyetsweb/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def ban_new_ip(self, ip):
def clear_fw(self):
logging.info("Clearing firewall rules")
self.session.put(self.endpoint, json=[{"ip": "192.168.3.1"}])
logging.info("Clearing cache from redis")
self.r.delete(self.key)


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions yyetsweb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func resource(c *gin.Context) {
var data map[string]interface{}
json.Unmarshal([]byte(result), &data)

c.JSON(200, data)

c.JSON(200, gin.H{
"data": data,
})
}

func entrance(c *gin.Context) {
Expand Down Expand Up @@ -168,6 +169,7 @@ func douban(c *gin.Context) {
c.Writer.Header().Add("content-type", "image/jpeg")
_, _ = c.Writer.Write(doubanPoster)
} else {
c.Writer.Header().Add("content-type", "application/json")
c.String(http.StatusOK, doubanInfo)
}

Expand Down

0 comments on commit e740af4

Please sign in to comment.