0

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.

2
  • possibly duplicate: stackoverflow.com/questions/56975/… and stackoverflow.com/questions/5630323/… Commented Jun 3, 2011 at 3:26
  • @user492238 Thanks for your suggestions. both of them specific to sending bulk emails. But my question is just not only sending email. Increasing pagetimeout works fine. But this also increase the waiting time for users. I am looking for async workflow. Commented Jun 3, 2011 at 4:01

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.