开发者

Asp.Net Web Based Work Flow

Scenario:

I am developing a web based application. In my application, users request article writing service from copywriters. Then copywriters will proceed with creation and submit the article back to client. Then client can approve or reject the articles. All these actions have status.

Business Problem:

01.I need to (example actions given below)

02.Send notifications (emails) when an article status changed.

03.Update copywriter’s profiles based on their performance (e.g.: rejections vs. approved) in the database.

04.Notify application admin if a certain article has been rejected x number of times.

05.In future there may be more business logic will be added.

Basically all flow is either an email sending or database calls.

My Approach:

I have come up with one function in my middle tier (yes my app is 3 tier.).

    Public Sub ExecuteWorkFlow(ByVal requestid As Integer, ByVal oldStatus As ServiceStatus, ByVal newStatus As ServiceStatus)

    Try
            If oldStatus.Value = ServiceStatus.InProgress Then
                If newStatus = ServiceStatus.PendingReview Then
                    'Update Logic
                ElseIf newStatus = ServiceStatus.Completed Then
                    'Update Logic
                End If
            End If

            'Check for rejected work flow. Send email to copywriters (and us if 3 rejection)
            If newStatus = ServiceStatus.Rejected Then
                If oldStatus.Value = ServiceStatus.PendingReview Then

                    'send email
                    SendRejectServieRequestEmail()

                    Dim rejects = From r In request.ServiceRequestHistory Where r.NewStatus = ServiceStatus.Rejected Select r

                    If rejects.Count() >= 3 Then 'Send email to admin
                        'send email
                        SendRejectServieEmailToAdmin()
    开发者_运维技巧                End If
                End If
            End If

        End If

        'Check for new job workflow. Send emails to providers.
        If oldStatus.HasValue = True Then
            If oldStatus.Value = ServiceStatus.UserEditing Then
                    'Get all copywriters
                    For Each p In copywriters
                        'Send email
                    Next
                End If
            End If
        End If

    Catch ex As Exception

    End Try
End Sub

This gives following advantages,

Inside logic can be changed with less effort.

Whole flow is managed in single location.

But:

This is sequential. And sending email in a for loop will take considerable time. But it’s too big to complete with in an asp.net post back time.

I am using SmtpClient as mailing tool. But sending async is not supported in middle tier.

Expecting solution

Is there any way to send email async from asp.net but not is page (from middle tier)?

Is there any other better workflow solution approach for web based solution?

I don't my answers in C# or vb.net. I am using .net 4.0

Additional Comments

I need to update database regarding this statuses. Not only just sending emails.


You have few options to address asynchronous emailing:

  • Launch the email sending part in a different thread (e.g. uisng ThreadPool.QueueUserWorkItem) and return the page immediately. Only issue is that in case of failures, you cannot easily update user back. There can be other issues such as your threads getting killed (due to pool/IIS/machine re-start) before email is sent.
  • Create a persistent queue (store it in database/file system etc) and run a separate service/job to sending emails. This is very reliable way and success/attempts/failures can be tracked at queue location, so updating the status back to user is simple.
  • A variation of above options where you use queuing provided by MSMQ.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜