2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-09-19 18:49:01 +00:00

Merge pull request #549 from vrslev/refactor-worker-commands

refactor(frappe-worker): Replace basic commands with bench
This commit is contained in:
Revant Nandgaonkar 2021-11-09 04:12:58 +05:30 committed by GitHub
commit 358293afc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 143 deletions

View File

@ -1,11 +0,0 @@
from frappe.utils.scheduler import start_scheduler
def main():
print("Starting background scheduler . . .")
start_scheduler()
exit(0)
if __name__ == "__main__":
main()

View File

@ -1,39 +0,0 @@
import os
import frappe
from frappe.utils.backups import scheduled_backup
from frappe.utils import cint, get_sites, now
def backup(sites, with_files=False):
for site in sites:
frappe.init(site)
frappe.connect()
odb = scheduled_backup(
ignore_files=not with_files,
backup_path_db=None,
backup_path_files=None,
backup_path_private_files=None,
force=True
)
print("database backup taken -", odb.backup_path_db, "- on", now())
if with_files:
print("files backup taken -", odb.backup_path_files, "- on", now())
print("private files backup taken -", odb.backup_path_private_files, "- on", now())
frappe.destroy()
def main():
installed_sites = ":".join(get_sites())
sites = os.environ.get("SITES", installed_sites).split(":")
with_files = cint(os.environ.get("WITH_FILES"))
backup(sites, with_files)
if frappe.redis_server:
frappe.redis_server.connection_pool.disconnect()
exit(0)
if __name__ == "__main__":
main()

View File

@ -1,32 +0,0 @@
import sys
import frappe
import IPython
from frappe.utils import get_sites
def console(site):
"Start ipython console for a site"
if site not in get_sites():
print("Site {0} does not exist on the current bench".format(site))
return
frappe.init(site=site)
frappe.connect()
frappe.local.lang = frappe.db.get_default("lang")
all_apps = frappe.get_installed_apps()
for app in all_apps:
locals()[app] = __import__(app)
print("Apps in this namespace:\n{}".format(", ".join(all_apps)))
IPython.embed(display_banner="", header="")
def main():
site = sys.argv[-1]
console(site)
if frappe.redis_server:
frappe.redis_server.connection_pool.disconnect()
if __name__ == "__main__":
main()

View File

@ -1,39 +0,0 @@
import os
import frappe
from frappe.commands.site import _drop_site
from constants import ARCHIVE_SITES_PATH
from utils import get_password
def main():
site_name = os.environ.get("SITE_NAME", 'site1.localhost')
db_root_username = os.environ.get("DB_ROOT_USER", 'root')
mariadb_root_password = get_password("MYSQL_ROOT_PASSWORD", 'admin')
postgres_root_password = get_password("POSTGRES_PASSWORD")
db_root_password = mariadb_root_password
if postgres_root_password:
db_root_password = postgres_root_password
force = True if os.environ.get("FORCE", None) else False
no_backup = True if os.environ.get("NO_BACKUP", None) else False
frappe.init(site_name, new_site=True)
_drop_site(
site=site_name,
root_login=db_root_username,
root_password=db_root_password,
archived_sites_path=ARCHIVE_SITES_PATH,
force=force,
no_backup=no_backup
)
if frappe.redis_server:
frappe.redis_server.connection_pool.disconnect()
exit(0)
if __name__ == "__main__":
main()

View File

@ -1,12 +0,0 @@
import os
from frappe.utils.background_jobs import start_worker
def main():
queue = os.environ.get("WORKER_TYPE", "default")
start_worker(queue, False)
exit(0)
if __name__ == "__main__":
main()

View File

@ -102,17 +102,16 @@ case "$1" in
worker)
checkConfigExists
checkConnection
# default WORKER_TYPE=default
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/worker.py
: "${WORKER_TYPE:=default}"
bench worker --queue $WORKER_TYPE
;;
schedule)
checkConfigExists
checkConnection
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/background.py
bench schedule
;;
new)
@ -127,8 +126,24 @@ case "$1" in
checkConfigExists
checkConnection
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/drop.py
exit
: "${SITE_NAME:=site1.localhost}"
: "${DB_ROOT_USER:=root}"
: "${DB_ROOT_PASSWORD:=$POSTGRES_PASSWORD}"
: "${DB_ROOT_PASSWORD:=$MYSQL_ROOT_PASSWORD}"
: "${DB_ROOT_PASSWORD:=admin}"
if [[ -n $NO_BACKUP ]]; then
NO_BACKUP=--no-backup
fi
if [[ -n $FORCE ]]; then
FORCE=--force
fi
bench drop-site \
$SITE_NAME \
--root-login $DB_ROOT_USER \
--root-password $DB_ROOT_PASSWORD \
--archived-sites-path /home/frappe/frappe-bench/sites/archive_sites \
$NO_BACKUP $FORCE
;;
migrate)
@ -142,9 +157,13 @@ case "$1" in
;;
backup)
if [[ -n $WITH_FILES ]]; then
WITH_FILES=--with-files
fi
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/backup.py
exit
for site in ${$SITES//:/ }; do
bench --site $site backup $WITH_FILES
done
;;
console)
@ -154,8 +173,7 @@ case "$1" in
exit 1
fi
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/console.py "$2"
exit
bench --site "$2" console
;;
push-backup)