@@ -0,0 +1,1724 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import unicode_literals%0A%0Afrom django.db import models, migrations%0A%0Adef advance_stuck_runs(apps, schema_editor):%0A%0A    # this data migration is not forward-compatible%0A    from temba.flows.models import Flow, FlowStep, FlowRun, RuleSet%0A    from temba.msgs.models import Msg%0A%0A    flows = Flow.objects.filter(flow_type='F')%0A    for flow in flows:%0A%0A        # looking for flows that start with a passive ruleset%0A        ruleset = RuleSet.objects.filter(uuid=flow.entry_uuid, flow=flow).first()%0A%0A        if ruleset and not ruleset.is_pause():%0A%0A            # now see if there are any active steps at our current flow%0A            steps = FlowStep.objects.filter(run__is_active=True, step_uuid=ruleset.uuid, rule_value=None, left_on=None).select_related('contact')%0A%0A            if steps:%0A%0A                flow.ensure_current_version()%0A                steps = FlowStep.objects.filter(run__is_active=True, step_uuid=ruleset.uuid, rule_value=None, left_on=None).select_related('contact')%0A%0A                if steps:%0A                    print '%5CnAdvancing %25d steps for %25s:%25s' %25 (len(steps), flow.org.name, flow.name)%0A                    for idx, step in enumerate(steps):%0A%0A                        if (idx+1) %25 100 == 0:%0A                            print '%5Cn%5Cn *** Step %25d of %25d%5Cn%5Cn' %25 (idx+1, len(steps))%0A%0A                        # force them to be handled again%0A                        msg = Msg(contact=step.contact, text='', id=0)%0A                        Flow.handle_destination(ruleset, step, step.run, msg)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('flows', '0023_new_split_dialog'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(advance_stuck_runs)%0A    %5D%0A

Add migration for stuck runs