Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job nodes can't be connected directly to the Start nodes #153

Closed
boakley opened this issue Jul 22, 2016 · 8 comments
Closed

Job nodes can't be connected directly to the Start nodes #153

boakley opened this issue Jul 22, 2016 · 8 comments

Comments

@boakley
Copy link

boakley commented Jul 22, 2016

In trying to debug why my celery task doesn't seem to do anything I realized that my code was hitting this block in flow_task_decorator:

except flow_task.flow_cls.task_cls.DoesNotExist:
    # There was rollback on job task created transaction,
    # we don't need to do the job
    return

This causes the body of the celery task to do nothing. There is no output, no log message, no indication whatsoever that there's a problem. The celery log shows that it received, accepted and completed the task, but because the decorator returned nothing, nothing actually executed.

Also, that comment means absolutely nothing to me as a user of viewflow. No rollback has been done to my task (at least, not intentionally), and I have no idea how to fix this problem.

I'm guessing this is related to the fact I'm creating the task from the following custom view:


# flows.py
class DistributorAuditFlow(Flow):
    process_title = "Distributor Audit"
    process_cls = DistributorAuditProcess
    summary_template = '{{ process.title }}'
    lock_impl = lock.select_for_update_lock

    start = (
        # flow.Start(StartProcessView,
        #          fields=["distributor", "days_ago_modified"],
        flow.Start(distributor_audit_view,
                   task_title="Distributor Audit",
                   task_description="Perform an audit of one of our distributors")
        .Permission(auto_create=True)
        .Next(this.run_audit)
    )

    run_audit = (viewflow.contrib.celery.Job(send_hello_world_request)
                 .Next(this.view_results)
    )
    ...

# views.py
@flow_start_view()
def distributor_audit_view(request, activation):
    activation.prepare(request.POST or None, user=request.user)
    form = DistributorAuditForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        slug = form.cleaned_data["distributor"].slug
        report_file = form.cleaned_data["report_file"]
        days_ago_modified = form.cleaned_data["days_ago_modified"]
        distributor = form.cleaned_data["distributor"]
        audit_worker = AUDIT_WORKERS[slug]

        activation.process.days_ago_modified = days_ago_modified
        activation.process.distributor = distributor
        activation.process.report_file = report_file
        activation.done()

        # FIXME: redirect to the current view, and modify the html to either show
        # a link to the generated file, or show "processing..." or something to that effect
        return HttpResponse("form was processed")

    return render(request, 'viewflow/flow/task.html',{
                  'form': form,
                  'activation': activation
                  })
@kmmbvnr
Copy link
Contributor

kmmbvnr commented Jul 23, 2016

What database do you use? Does it have 'select .. for update' functionality?

Generally task.DoesNotExist could happens b/c celery task started before view code finish and commit. That could happens if lock is not working.

@kmmbvnr
Copy link
Contributor

kmmbvnr commented Jul 23, 2016

Sorry, that seems a bug in viewflow. Start nodes do no locking at all, so celery task could start before start view commit the process and task instances

@kmmbvnr kmmbvnr changed the title bug in flow_task_decorator Job nodes can't be connected directly to the Start nodes Jul 23, 2016
@kmmbvnr
Copy link
Contributor

kmmbvnr commented Jul 24, 2016

-pro: 0.10.5 released. Due design flaws in 0.10 the only case for (StartView -> Job) could be fixed.

@kmmbvnr
Copy link
Contributor

kmmbvnr commented Jul 24, 2016

btw @boakley you can simplify your view by implementing DistributorAuditForm as model form

class DistributorAuditForm(forms.ModelForm):
    class Meta:
        model = DistributorAuditProcess
        fields = ['report_file', 'days_ago_modified', 'distributor']

@flow_start_view()
def distributor_audit_view(request, activation):
    activation.prepare(request.POST or None, user=request.user)
    form = DistributorAuditForm(
            request.POST or None,
            request.FILES or None,
            instance=activation.process)
    if form.is_valid():
        form.save(commit=False)
        activation.done()
        return redirect(...)
   return render(...)

@boakley
Copy link
Author

boakley commented Jul 26, 2016

This doesn't seem to have solved my problem. I upgraded to viewflow-pro 0.10.5, but my tasks still don't do anything. They are still hitting this block of code in job.py:

        except flow_task.flow_cls.task_cls.DoesNotExist:
            # There was rollback on job task created transaction,
            # we don't need to do the job
            return

@kmmbvnr
Copy link
Contributor

kmmbvnr commented Aug 9, 2016

I've got the problem.

At the time when flow task is schedulled, the process instance are not commuted. So select_for_update lock wont work in the celery task,

The only solution for now as i see - is to switch to redis based locks

@kmmbvnr
Copy link
Contributor

kmmbvnr commented Aug 9, 2016

I fixed the issue with select_for_update lock 0.10.6.pro released

@kmmbvnr
Copy link
Contributor

kmmbvnr commented Aug 12, 2016

0.10.7.pro released with fix for cache_lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants