celery_tasks.py
Python script, ASCII text executable
1import time 2import os 3import config 4from celery import shared_task 5from app import db 6from misc_utils import * 7from models import * 8from smtplib import SMTP 9 10 11@shared_task(ignore_result=False) 12def send_notification(notification_id, users, level): 13notification = db.session.get(Notification, notification_id) 14 15for user in users: 16db.session.add(UserNotification(db.session.get(User, user), notification, level)) 17db.session.commit() 18 19return 0 # notification sent successfully 20 21 22@shared_task(ignore_result=False) 23def merge_heads(head_route, head_branch, base_route, base_branch): 24server_repo_location = os.path.join(config.REPOS_PATH, base_route.lstrip("/")) 25if not os.path.isdir(server_repo_location): 26raise FileNotFoundError(f"Repo {server_repo_location} not found, cannot merge.") 27 28if base_route == head_route: 29git_command(server_repo_location, b"", "checkout", f"{base_branch}") 30out, err = git_command(server_repo_location, b"", "merge", "--no-ff", f"heads/{head_branch}", return_err=True) 31 32return out, err 33 34remote_url = os.path.join(config.BASE_DOMAIN, "git", base_route.lstrip("/")) 35 36git_command(server_repo_location, b"", "remote", "add", "NEW", remote_url) 37git_command(server_repo_location, b"", "remote", "update") 38git_command(server_repo_location, b"", "checkout", f"{base_branch}") 39git_command(server_repo_location, b"", "merge", "--allow-unrelated-histories", f"NEW/{head_branch}") 40git_command(server_repo_location, b"", "remote", "rm", "NEW") 41