mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Use sqlalchemy events to emit jsonpatches to the client.
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
from .. import db, socketio
 | 
			
		||||
from .. import db
 | 
			
		||||
from ..decorators import background
 | 
			
		||||
from ..models import Job
 | 
			
		||||
 | 
			
		||||
@@ -9,12 +9,8 @@ def delete_job(job_id, *args, **kwargs):
 | 
			
		||||
        job = Job.query.get(job_id)
 | 
			
		||||
        if job is None:
 | 
			
		||||
            raise Exception('Job {} not found'.format(job_id))
 | 
			
		||||
        event = 'user_{}_patch'.format(job.user_id)
 | 
			
		||||
        jsonpatch = [{'op': 'remove', 'path': '/jobs/{}'.format(job.id)}]
 | 
			
		||||
        room = 'user_{}'.format(job.user_id)
 | 
			
		||||
        job.delete()
 | 
			
		||||
        db.session.commit()
 | 
			
		||||
        socketio.emit(event, jsonpatch, room=room)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@background
 | 
			
		||||
@@ -29,8 +25,3 @@ def restart_job(job_id, *args, **kwargs):
 | 
			
		||||
            pass
 | 
			
		||||
        else:
 | 
			
		||||
            db.session.commit()
 | 
			
		||||
            event = 'user_{}_patch'.format(job.user_id)
 | 
			
		||||
            jsonpatch = [{'op': 'replace', 'path': '/jobs/{}/end_date'.format(job.id), 'value': job.end_date.timestamp()},  # noqa
 | 
			
		||||
                         {'op': 'replace', 'path': '/jobs/{}/status'.format(job.id), 'value': job.status}]  # noqa
 | 
			
		||||
            room = 'user_{}'.format(job.user_id)
 | 
			
		||||
            socketio.emit(event, jsonpatch, room=room)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user