Persistence of WF workflow instances

Source: Internet
Author: User
WF workflow instance persistence (passivation) is very important in workflow projects. In actual business, almost all business flows can be completed after a long time, in this way, the unfinished business flow needs to be persisted to the database or file.

WF itself provides the sqlworkflowpersistenceservice service to support instance persistence.

Public
Sqlworkflowpersistenceservice (string connectionstring, bool unloadonidle,
Timespan instanceownershipduration, timespan loadinginterval)

Parameter description:
Connectionstring: database connection string
Unloadonidle: whether to enable automatic Passivation

Instanceownershipduration: Lock duration
Loadinginterval: Engine polling detection Interval

There is no need to talk about database connection strings. The key lies in the following three parameters.
The unloadonidle is set to true in the example provided by Ms. The advantage is that the workflow engine automatically implements (Perform persistence during idle time). Generally, I set it to false and use the workflowruntime idled event to complete persistence.
I once saw a friend on the internet saying that setting true will cause a very bad problem: Once the instance is persistent, we cannot use it after retrieve the database, the specific manifestation is that the workflow cannot receive events initiated by the caller. It seems that this problem does not exist after testing. At least this problem is not found currently (it is also possible that the WF attached to vs2008 RTM does not exist)

Instanceownershipduration, this violates the workflow principle (a statement of the family ). Adjust the length of time according to the service type.

Loadinginterval, from the event probe, we can see that workflowruntime does not properly access the database.

the sqlworkflowpersistenceservice service depends mainly on the instancestate and completedscope
the instancestate table to record the workflow instances that have not been completed, and completedscope assists in the support of wage flow transactions.
instancestate table field Description:
uidinstanceid: instance id. We recommend that you bind it with the Business Document ID, if your system uses an int or another type of primary key, it will be more difficult.
state: the persistent content of the workflow instance. From the current test, it is not simply the content of the workflow instance. Other things may be added, because I have not learned how to customize workflowpersistenceservice, it is not clear which data is stored in this field.
Status: status. I don't know what to do, because his value is always 0 during the test.
unlocked: the value of unlocked is always 1.
blocked: whether the instance is locked.
info: it is always blank and has unknown meaning
ownerid: instance owner, which is the "who" load the instance, is the unique ID generated by workflowruntime and the current application. The value of the winform application host after each loading is different. For a WCF or WebService host workflow, the value remains unchanged as long as the bearer that these services are not used does not restart, after workflowruntime is restarted, a new ownerid is generated.
owneduntil: expiration time of the Instance held by the owner. This value is consistent with instanceownershipduration parameter is associated with the instance retrieve time plus instanceownershipduration is the value of
owneduntil.
nexttimer: The expiration time of the instance. The value ranges from 9999 to 12-31 23:59:59. You do not know which actions will affect the instance.

In a workflow project, you can create a workflow, create a workflow instance, load a workflow instance, and call events ....

When creating a workflow or instance,
Instancestate table
Blocked is 0,
Ownerid,
All owneduntil values are null;
When loading, blocked is 1,
Ownerid,
Owneduntil has written the corresponding value not blank;

If blocked is 0,
Ownerid,
An instance whose owneduntil is null can be loaded by any engine, because there is no "person" using it.
If blocked is 1,
Ownerid,
If owneduntil is not null, it indicates that the instance has been loaded and locked by an engine, so that other instances cannot be operated. If you forcibly call the instance, it will reportSystem. workflow. Activities. eventdeliveryfailedexception
Error,Innerexception: system. workflow. runtime. queueexception.
If blocked is 1,
Ownerid,
If owneduntil is null, the database has been repersisted and can be used by other engines.

Next, we will sort out the examples for testing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.