misc: use hobo.multitenant.spooler (#76430)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-04-08 14:45:44 +02:00
parent 98a0cd8470
commit 225c76f191
4 changed files with 34 additions and 33 deletions

3
debian/uwsgi.ini vendored
View File

@ -13,8 +13,7 @@ chmod-socket = 666
vacuum = true vacuum = true
spooler-processes = 3 spooler-processes = 3
spooler-python-import = hobo.provisionning.spooler spooler-python-import = hobo.multitenant.spooler
spooler-python-import = passerelle.utils.spooler
spooler-max-tasks = 20 spooler-max-tasks = 20
# every five minutes # every five minutes

View File

@ -7,6 +7,7 @@ import itertools
import logging import logging
import os import os
import re import re
import subprocess
import sys import sys
import traceback import traceback
import uuid import uuid
@ -36,7 +37,7 @@ from model_utils.managers import InheritanceManager as ModelUtilsInheritanceMana
import passerelle import passerelle
from passerelle.forms import GenericConnectorForm from passerelle.forms import GenericConnectorForm
from passerelle.utils import ImportSiteError from passerelle.utils import ImportSiteError, spooler
from passerelle.utils.api import endpoint from passerelle.utils.api import endpoint
from passerelle.utils.jsonresponse import APIError from passerelle.utils.jsonresponse import APIError
from passerelle.utils.sftp import SFTP, SFTPField from passerelle.utils.sftp import SFTP, SFTPField
@ -849,13 +850,33 @@ class Job(models.Model):
self.status_details.update({'new_job_pk': new_job.pk}) self.status_details.update({'new_job_pk': new_job.pk})
self.save() self.save()
@classmethod
def run_with_subprocess(cls, job_id):
tenant = getattr(connection, 'tenant', None)
domain = getattr(tenant, 'domain_url', None)
cmd_args = [
settings.PASSERELLE_MANAGE_COMMAND,
]
if domain:
# multitenant installation
cmd_args.append('tenant_command')
cmd_args += ['runjob', '--job-id', str(job_id)]
if domain:
# multitenant installation
cmd_args.append('--domain')
cmd_args.append(domain)
# pylint: disable=subprocess-run-check
subprocess.run(cmd_args)
def run(self, spool=False): def run(self, spool=False):
if spool and self.pk: if spool and self.pk:
if 'uwsgi' in sys.modules and settings.PASSERELLE_MANAGE_COMMAND: if settings.PASSERELLE_MANAGE_COMMAND:
from passerelle.utils.spooler import run_job spooler.run(Job.run_with_subprocess, job_id=self.pk)
tenant = getattr(connection, 'tenant', None)
run_job.spool(job_id=str(self.pk), domain=getattr(tenant, 'domain_url', None))
return return
self.status = 'running' self.status = 'running'

View File

@ -291,6 +291,7 @@ LOGGED_REQUESTS_MAX_SIZE = 5000
# Number of days to keep logs # Number of days to keep logs
LOG_RETENTION_DAYS = 7 LOG_RETENTION_DAYS = 7
USE_NEW_SPOOLER = True
LOGGING = { LOGGING = {
'version': 1, 'version': 1,

View File

@ -14,29 +14,9 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import subprocess try:
from hobo.multitenant.spooler import run # pylint: disable=unused-import
except ImportError:
from uwsgidecorators import spool # pylint: disable=import-error def run(func, *args, **kwargs):
func(*args, **kwargs)
@spool
def run_job(args):
from django.conf import settings
cmd_args = [
settings.PASSERELLE_MANAGE_COMMAND,
]
if args.get('domain'):
# multitenant installation
cmd_args.append('tenant_command')
cmd_args += ['runjob', '--job-id', args['job_id']]
if args.get('domain'):
# multitenant installation
cmd_args.append('--domain')
cmd_args.append(args['domain'])
# pylint: disable=subprocess-run-check
subprocess.run(cmd_args)