Execute a transition a specific date with NServiceBus - nservicebus

I'm working on a system where the lifetime of a subscription is handle with a state machine and I'm looking at NServiceBus as a replacement for the management of transitions between states.
Example
A customer has an active internet subscription and would like to cancel it 3 months in the future.
Current Solution
A transition is created in the database e.g.
tranistionId: 10000,
subscriptionId: 1337,
transition: "execute-inactivation"
due-date: {current date + 3 months}
The table is scanned every 10s to see if there are any new/due transitions.
NServiceBus
I think it would be possible to replicate the current solution with:
Schedule.Every(TimeSpan.FromSeconds(5)).Action(() =>
{
Bus.Send<CheckForDueTransitions>();
});
But that will not remove the problem with the chattiness against the database.
Another important feature is that's possible to a abort a queued transition e.g. cancel the cancellation.
Is there a preferred NServiceBus solution for my problem?

I would suggest looking at NServiceBus Sagas. You might think of each subscription being its own long running process (Saga instance), and using the Timeout Manager to manage them. You could then use the timeout functionality to cancel your subscriptions automatically, on-demand, or if a users extends their subscription, create a new timeout for that subscription to the new expiry date.

Related

android studio call a functoin with alarm manager

I'm making an app in kotlin that query an API once a day with alarm manager.
Now I thought of a problem: what to do if there is no internet connection when the alarm manager is executed?
My best idea is to query the API and if there is no response I would set another alarm manager to half an hour later.
the problem is that the alarm manager needs a pending intent and I don't know how to call another function in the activity with a pending intent.
I can just call the same activity with another intent, but I'm afraid that if there won't be internet connection several times in a row something bad will happen because there will be to many intents.
So my question is if the bad thing will actually happen because of all the intents
or maybe you have a better solution than mine...
You should use WorkManager for this purpose. It is designed to support these kinds of tasks. You can schedule periodic execution and tell WorkManager that your task needs Internet connectivity. WorkManager ensures that the task only runs when there is connectivity. Tasks scheduled with WorkManager are persisted across device restarts so you don't have to worry about rescheduling them after a device reboot.
See https://developer.android.com/topic/libraries/architecture/workmanager

Schedule a background task (Cron Job) for a specific date and time

I am creating an ASP NET Core app, and I have certain entities, for example, a dispute for an order. After the dispute has been opened, the Creation Date property is set for it. I want to make sure that if the buyer does not answer in his dispute within 7 days, the dispute is closed automatically.
I understand that it can be done through CronJob with a certain interval, but I would like to avoid an excessive number of calls to check the date in all disputes.
Is there a proper way to schedule task calls at a specific time? I need it workable even after app restarting.
Is there a proper way to schedule task calls at a specific time?
To execute a background task/job at a user specified time, you can try to use some message queue services, such Azure Queue Storage queues that enable us to specify how long the message should be invisible to Dequeue and Peek operations by setting visibilityTimeout.
And you can implement a queue triggered background task to retrieve message(s) from the queue and close the dispute in code logic.

Is there a way to get confirmation from the scheduler that the job has been accepted?

I'm using dask.distributed.Client to connect to a remote Dask scheduler running that manages a bunch of workers. I am submitting my job using client.submit and keeping track of the returned Future:
client = Client("some-example-host:8786")
future = client.submit(job, job_args)
I want to be able to know if/when the job has been sent to and accepted by the scheduler. This is so that I can add some retry logic in cases when the scheduler goes down.
Is there an easy way to get confirmation that the scheduler has received and accepted the job?
Some additional points:
I realise that distributed.client.Future has a status property, but I'm hesitant to use it as it was not documented in the API.
I have tried using dask.callbacks.Callback but with no success. Any assistance with using callbacks with distributed.Client would be appreciated.
EDIT: I could also have the job post back a notification when it starts, but I would like to leave this approach as a last resort if the Client does not support this.

ActiveMQ - Update on Connect?

I'm working with ActiveMQ to implement some notification solutions in the emergency management / public safety sphere. Right now I'm setting up a topic to move updates to an OpenLayers map using Stomp over websockets.
My question is... is there a way to ensure that each consumer gets the most recent message on connect? I have it in mind to push updates every fifteen seconds or so, but I'd like folks to get the latest update when they connect and not have to wait till the next scheduled push.
Anything is possible, of course, so I guess my question is "is that feasible without a lot of pain?"
TIA,
Art
You have a durable subscription but this backup all messages sent when consumer is offline, you can setup the expiry time for messages to be short to be discarded when consumer reconnect or use the retroactive consumer http://activemq.apache.org/retroactive-consumer.html

Long running workflow in asp.net mvc

I'm developing an intranet site using asp.net mvc4 to manage some of our data. One important feature of this site is to trigger import/export jobs. These jobs can take anywhere between 5 minutes to 1 hour. Users of the site need to be able to determine whether a job is currently running as well as the status of prior jobs. Many jobs will often include warning messages concerning duplicate data and these warnings need to be visible on the site.
My plan is to implement these long running processes as a WCF Workflow Service that the asp.net site will interact with. I've got much of the business logic implemented via activities and have tested it using a simple console application. I should note I'm using a correlation handle in order to partition the service based on specific "Projects" on the site.
My problem is how do I go by querying the status of an active job (if one exists) as well as the warning messages of previous jobs. I suspect the best way to do this would be to use the AppFabric tracking service and have my asp.net query a SQL monitoring store and report back on the current status. After setting up AppFabric and adding custom tracking messages, I ran into a few issues. My first issue is that I cannot figure out how to filter out workflow instances that were not using the correct correlation handle as I'd like to show only workflows for a specific project. The other issue is that the tracking database can be delayed quite a bit which causes issues for me trying to determine if a workflow is currently running.
Another possible solution could be to have the workflow explicitly update a database with its current status and any error messages. I'm leaning towards this solution but could use some expert advice.
TL;DR: I need to know the best way to query the execution status and any warning messages of a WCF Workflow service.
As you want to query workflow status and messages even after the workflow is finished I would start by creating a table where you can convert the correlation values a client send to the related workflow ID. I would create a custom activity to do that and drop it right after the receive that creates the workflow.
Next I would create a regular WCF service the client app uses to query the status. This WCF service can query the WF persistence store to see if a given workflow is still running. If so the active bookmarks column will tell you what SOAP messages the workflow is currently waiting for.
As far as messages go you can either use the AppFabric tracking infrastructure to store and retrieve them or you could create a custom activity and store them in your own database. It really depends if you are also interested in the standard WF tracking messages generated.
Update on cheking for running workflow instances:
There are several downsides to adding an IsRunning message to your workflow. For one you would need to make sure one branch keeps looping and waiting for the message but stops as soon as the other real workflow branch is done. Certainly possible but it complicates the workflow and is a possible source of errors. And as it is not part of the business problem it really has no place in the workflow as far as I am concerned. It also means that you will have to load a workflow from disk and persist it back just to tell you that it is there. If it was finished you will need to wait for a fault to indicate there was no workflow instance. And that usually means you get a timeout exception after, by default, 60 seconds. Add throttling to that and you request might be queued because there are too many other workflow instances or SOAP request being processed. So a timeout might mean that a workflow instance exists but is unreachable due to system constraints. Instead I would opt for the simple thing and check if the record in the instance store is still available. The additional info from the active bookmarks column will tell you what the workflow is waiting on, information I have used in the past to dynamically update the UI by enabling/disabling UI elements.