<s> from __future__ import absolute_import <EOL> from django . db . models . signals import post_delete , pre_save , post_save <EOL> from django . db . utils import InterfaceError , DatabaseError <EOL> from django import db <EOL> from celery . signals import task_postrun , task_prerun , task_revoked <EOL> @ task_postrun . connect <EOL> @ task_prerun . connect <EOL> def task_completed ( sender = None , ** kwargs ) : <EOL> task_kwargs = kwargs . get ( '<STR_LIT>' ) <EOL> job_id = task_kwargs . get ( '<STR_LIT>' ) <EOL> if not job_id : <EOL> return <EOL> from . models import WooeyJob <EOL> from celery import states <EOL> try : <EOL> job = WooeyJob . objects . get ( pk = job_id ) <EOL> except ( InterfaceError , DatabaseError ) as e : <EOL> db . connection . close ( ) <EOL> job = WooeyJob . objects . get ( pk = job_id ) <EOL> state = kwargs . get ( '<STR_LIT:state>' ) <EOL> if state : <EOL> job . status = WooeyJob . COMPLETED if state == states . SUCCESS else state <EOL> job . celery_id = kwargs . get ( '<STR_LIT>' ) <EOL> job . save ( ) <EOL> from . models import ScriptVersion <EOL> def skip_script ( instance ) : <EOL> return getattr ( instance , '<STR_LIT>' , False ) or getattr ( instance , '<STR_LIT>' , False ) or getattr ( instance , '<STR_LIT>' , False ) <EOL> def script_version_presave ( instance , ** kwargs ) : <EOL> created = instance . pk is None <EOL> if not created : <EOL> if '<STR_LIT>' in instance . changed_fields and not skip_script ( instance ) : <EOL> instance . script_iteration += <NUM_LIT:1> <EOL> instance . _script_upgrade = True <EOL> instance . pk = None <EOL> def script_version_postsave ( instance , created , ** kwargs ) : <EOL> from . backend import utils <EOL> if created and ( not skip_script ( instance ) or getattr ( instance , '<STR_LIT>' , False ) ) : <EOL> res = utils . add_wooey_script ( script_version = instance , group = instance . script . script_group ) <EOL> instance . _script_upgrade = False <EOL> instance . _script_cl_creation = False <EOL> instance . _rename_script = False <EOL> if res [ '<STR_LIT>' ] is False : <EOL> instance . delete ( ) <EOL> raise BaseException ( res [ '<STR_LIT>' ] ) <EOL> utils . reset_form_factory ( script_version = instance ) <EOL> pre_save . connect ( script_version_presave , sender = ScriptVersion ) <EOL> post_save . connect ( script_version_postsave , sender = ScriptVersion ) </s>
