How can I resume a persisted instance by a new version activity? - android-activity

I have a Workflow Activity to handle task operations. The flow of the activity is "Create->Detach->Accept->Finish". A new workflow instance will be created for each new task. And the unfinished instances are persisted into database.
And after several days I change the activity, append a new step "Verify" at the last of the flow, so now the new flow is "Create->Detach->Accept->Finish->Verify".
I found that I can't resume the persisted instance by the new version activity. While I attempt to load the persisted instance, an exception thrown. How can i resume old instance by the new version activity? I want that the unfinished task can be handled by the new flow.

Unfortunately there isn't much you can do about this in .NET 4. Soon in .NET 4.5 there are new APIs that will allow you to update the persisted instance to prevent this.

Related

Flutter: Executing a Task after App is Killed

I would like to execute some asynchronous code just before my Flutter App is killed by the OS due to low memory.
I am currently using the WidgetsBindingObserver mixin to listen to app lifecycle changes, and when the app is paused (before it is detached) start the code execution.
The code I'm trying to execute:
I am trying to commit something to a local cache using SharedPreferences, but to no avail. It doesn't end up committing the data.
The Potential Issues:
I'm not sure if it is primarily due to running code while the app is being detached - in which case it could be solved by using the WorkManager package.
Or, if it is related to accessing Shared Preferences after the app has already been detached.
Any help or insight would be welcome!
Unfortunately, using the WidgetsBindingObserver mixin doesn't work for my use-case. When the lifecycle status changes to detached, any asynchronous code executed after this is not able to complete in time.
I solved the problem using a local key-pair store called Hive to locally save the form data as it was inputted by the user. Then, when they are ready to resume the form completion, re-populate the form and allow them to continue filling it out.

First app start failed if there are some events in event store

I started an app with some events in event store. As I understand, read model building starts on first read model request. But of course on first start it is no ready yet, but state is returned instantly. So on the client side on each first page open after a server refresh I have an incorrect state that break down my client app.
My question is how can I avoid getting stale data on the client if read model is still being rebuilt?
At the moment, reSolve read model has no information if it is still building, therefore query resolver just use the current state of the read model, whatever it is.
Currently there is no way to wait for rebuild to finish, or to throw an error.
We've recorded an issue and will fix this in the future release.

AppFabric Hosted Workflow does not always reload after delay/unload

I have a WCF Windows Workflow (4.5) Workflow Service hosted under IIS and using AppFabric 1.1. The workflow instances are long-running (up to about a week), but much of the time is spent in Delay activities.
This seemed to work fine at first, but when running multiple instances of the workflow at the same time (2+ instances causes this), some of them just never wake up once they've unloaded from memory during the Delay step. When I look at the logs, the errors I find all look like this:
System.OperationCanceledException: The execution of InstancePersistenceCommands has been canceled because the InstanceHandle was freed.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.WaitAndHandleStoreEventsCallback(IAsyncResult result)
Unfortunately, I'm not finding any useful information on that error message.
The SuspensionExceptionName and SuspensionReason fields in the AppFabric Persisted Instances Table show System.NullReferenceException: Object reference not set to an instance of an object. But this doesn't happen inside my workflow, only outside.
Additional Info:
I'm running the activity as a Fire & Forget (receive activity, no send)
My workflow calls into other WCF services to fetch data.
I am running this on Server 2012 R2, IIS 8 (not azure)
Workflow Persistence is working. I can reset IIS, reboot... its just when I run 2 instances that it has problems.
I'm definitely not hitting any kind of throttling limits. While the workflow deals with a few MB of data, this issue happens at 2+ instances.
Any idea what might be happening here?
Edit:
I realized I found more information on how the issue operates and never added it to the question. When the delay issue happens, it operates a lot like a static variable getting written by 2 threads.
Here's a visualization:
WF1 Start ---->Do Stuff--->Sleep------------*1----->Cancelled Exception at some point
------WF 2 Start---->Do Stuff------->Sleep->Wake up---------*2------>More Stuff---->End Successfully
*1 - When WF Instance 1 Should Wake up (Same time as WF 2 wakes)
*2 - When WF Instance 2 Should have woken up (Seems to be ignored)
Before anyone asks... I got rid of every static variable, method, class in my code. Nothing is static anymore.
I've been struggling with similar issues for quite a while. I use WFW4 and I find similar errors when a workflow instance is in a long delay.
I don't know what the cause of the problem is, but I have a work around that you might find helpful.
In my case, the errors I get are from Workflow Management Service and say:
Failed to invoke service management endpoint at 'net.pipe://.svc' to activate service '/Alerts/Workflows/.xamlx'. Exception: 'Access is denied.'
These errors start happening sometime between 6 and 30 hours after the instance goes into a long delay.
I have found that if I create a new instance of the workflow when the first instance is in delay and the errors are happening, then Workflow Management Service is able to resume interacting with the first sleeping instance.
So, I made a new workflow whose sole purpose is to periodically launch and then kill instances of the workflow that contains the long delay.
It actually gets a bit more complicated to make this work. I wanted this new workflow to also go to sleep between times when it creates and kills a new instance of the first workflow. But this going to sleep causes the instance of the new workflow to suffer the same problem as the first workflow. So, I modified the new workflow so it does the following:
-- delay for some rather short period, such as 30 minutes
-- create an instance of the first workflow
-- wait a minute
-- kill the just-created instance of the first workflow
-- create a new instance of this new error-preventing workflow
-- terminate
Since having done this, I no longer get the Access is Denied error from Workflow Management Service!
Hope this helps
Turns out my first answer was not correct, but I believe this answer is right, and solves the issue ChrisG is having.
My workaround did not actually work. Took a while for the problem to resurface. 29 hours to be precise - the default time it takes for an app pool to recycle.
So for me, the solution was to make my app pool not recycle. When an app pool recycles while a workflow instance is in a delay activity, the workflowManagementService is not able to wake up the instance and throws Access is Denied errors. If you create a new instance of the workflow after the app pool has recycled, the first instance will pick up where it left off, but sometimes still has problems, which is what I believe is happening to ChrisG.
ChrisG, looking at your visualization, is it possible that an appPool is recycling during the time wf1 is sleeping? I believe that is the cause the exception. If you then launch a new wf instance after *2 has passed (and if an app pool recycle happened prior to *1), that will wake up both wf1 and wf2, but wf1 won't work properly (at least in my experience)
Also, this happens after iisresets and server reboots. To handle those, you need to use IIS7 which allows the web application (as well as the web site) which is hosting the xamlx files to autostart after an iisreset or server reboot. This option is not available in IIS6. See http://www.postseek.com/meta/991815402b369e71ce925cde47ac907d for details
Hope this helps!

Event-based JOb scheduling

I have a requirement to generate certain reports as and when the DB is updated (say new alerts have been generated or new users have been created etc). I have MySQL DB triggers that get fired when the tables get updated and my question is can I schedule a job that gets executed whenever the DB trigger fires off?
This is Java Spring based application and I am considering Quartz but so far I haven't been able to figure out if Quartz can trigger jobs based on DB triggers. I have come across a 'jBatchEngine' that says "In contrast to time driven schedulers like Cron, jBatchEngine is event driven". Has anyone done such event-based job scheduling with Quartz or any other tools? Please advise !!
Thanks much !!!

Windows Workflow: Persistence and Polling

I'm currently learning the WF framework, so bear with me; mostly I'm looking for where to start looking, not necessarily a direct answer. I just can't seem to figure out how to begin researching what I'd like in The Google.
Let's say I have a simple one-step workflow (much more complicated than that, but for simplicity's sake). This workflow needs to watch a certain record in the database to see when it changes. I don't have the capability to "push" via a trigger from the database when the row changes, so I need to poll for it every so often.
This workflow needs to be persisted to the database to be durable against restarts and whatnot as this is a long-running workflow. I'm trying to figure out the best way to get it to check every 3 minutes or so and also persist to the database. Do the persistence capabilities of the framework allow for that? It seems to be time-based. And since the workflow won't be reawakened by an external event, how does it reload from the database and check the same step it did previously again? Does it attempt the last unfulfilled activity automatically upon reloading?
Do "while" activities with a delay attached to it work at all, or can it be handled solely through the persistence services?
I'm not sure what you mean by "handled soley through persistence services"? Persistence refers only to the storing of an idle workflow.
You could have a Delay and a Code activity in a Sequence in a While loop. When in the Delay the workflow will go idle and may be persisted if necessary. However depending on how much state is needed when persisting the workflow and/or how many such workflows you would have running at any one time may mean that a leaner approach is necessary.
A leaner approach would be to externalise the DB watching and have some "DB watching" workflow service raise an event when the desired change has occured. This service would be added to Workflow runtime.
To that end you need a service contract which is defined by an Inteface with the [ExternalDataExchange] attribute. This interface in turn defines an event that the service will raise when the desired DB change is detected. It also defines a method that a Workflow can call to specify what what change this service should be looking for. The method should accept an instance GUID so that the requesting instance can be found when the DB change is detected.
In the workflow you use a CallExternalMethodActivity to call this services method. You then flow to a HandleExternalEventActivity which listen for the event. At this point the workflow will go idle and can be persisted. It will remain there until the service raises the event.