e.output is null on WF Completed event - c#-4.0

I am working with WF 4 and I want that when an activity failed, finshed the WF and send the callback to client with in/out argument.
but, on Completed event, the e.output is empty.
Why does it happen???

If your workflow failed there is no output. So either use the exception to pass data to the caller or handle the exception in the workflow and have it terminate normally.

Related

Java Card Applet trigger proactive CAT command in process method

I need to get the current time and reset the UICC in an APDU command processed in the process method of the Applet. I'm concerned about the statement in the uicc.toolkit.ProactiveHandlerSystem.getTheHandler() method:
The applet shall get the reference of the handler at its triggering, the beginning of
the processToolkit method.
I assume I will get a HANDLER_NOT_AVAILABLE ToolkitException when trying to get the handler anywhere else except the processToolkit method.
Has anyone experience with this?
What are the alternatives to get the time and execute the reset?
I could get the time in advance after the PROFILE DOWNLOAD event or in the last STATUS event before the process command is triggered. But this would mean to poll the time continuously even if the my APDU command is not called. I could wait for the next STATUS command and listen to it to execute the reset, but this would be a delay of 30 seconds.

Twilio Taskrouter: How to prevent last worker in queue from being reassigned rejected task?

I'm using NodeJS to manage a Twilio Taskrouter workflow. My goal is to have a task assigned to an Idle worker in the main queue identified with queueSid, unless one of the following is true:
No workers in the queue are set to Idle
Reservations for the task have already been rejected by every worker in the queue
In these cases, the task should fall through to the next queue identified with automaticQueueSid. Here is how I construct the JSON for the workflow (it includes a filter such that an inbound call from an agent should not generate an outbound call to that same agent):
configurationJSON(){
var config={
"task_routing":{
"filters":[
{
"filter_friendly_name":"don't call self",
"expression":"1==1",
"targets":[
{
"queue":queueSid,
"expression":"(task.caller!=worker.contact_uri) and (worker.sid NOT IN task.rejectedWorkers)",
"skip_if": "workers.available == 0"
},
{
"queue":automaticQueueSid
}
]
}
],
"default_filter":{
"queue":queueSid
}
}
}
return config;
}
This results in no reservation being created after the task reaches the queue. My event logger shows that the following events have occurred:
workflow.target-matched
workflow.entered
task.created
That's as far as it gets and just hangs there. When I replace the line
"expression":"(task.caller!=worker.contact_uri) and (worker.sid NOT IN task.rejectedWorkers)"
with
"expression":"(task.caller!=worker.contact_uri)
Then the reservation is correctly created for the next available worker, or sent to automaticQueueSid if no workers are available when the call comes in, so I guess the skip_if is working correctly. So maybe there is something wrong with how I wrote the target expression?
I tried working around this by setting a worker to unavailable once they reject a reservation, as follows:
clientWorkspace
.workers(parameters.workerSid)
.reservations(parameters.reservationSid)
.update({
reservationStatus:'rejected'
})
.then(reservation=>{
//this function sets the worker's Activity to Offline
var updateResult=worker.updateWorkerFromSid(parameters.workerSid,process.env.TWILIO_OFFLINE_SID);
})
.catch(err=>console.log("/agent_rejects: error rejecting reservation: "+err));
But what seems to be happening is that as soon as the reservation is rejected, before worker.updateWorkerFromSid() is called, Taskrouter has already generated a new reservation and assigned it to that same worker, and my Activity update fails with the following error:
Error: Worker [workerSid] cannot have its activity updated while it has 1 pending reservations.
Eventually, it seems that the worker is naturally set to Offline and the task does time out and get moved into the next queue, as shown by the following events/descriptions:
worker.activity.update
Worker [friendly name] updated to Offline Activity
reservation.timeout
Reservation [sid] timed out
task-queue.moved
Task [sid] moved out of TaskQueue [friendly name]
task-queue.timeout
Task [sid] timed out of TaskQueue [friendly name]
After this point the task is moved into the next queue automaticQueueSid to be handled by available workers registered with that queue. I'm not sure why a timeout is being used, as I haven't included one in my workflow configuration.
I'm stumped--how can I get the task to successfully move to the next queue upon the last worker's reservation rejection?
UPDATE: although #philnash's answer helped me correctly handle the worker.sid NOT IN task.rejectedWorkers issue, I ultimately ended up implementing this feature using the RejectPendingReservations parameter when updating the worker's availability.
Twilio developer evangelist here.
rejectedWorkers is not an attribute that is automatically handled by TaskRouter. You reference this answer by my colleague Megan in which she says:
For example, you could update TaskAttributes to have a rejected worker SID list, and then in the workflow say that worker.sid NOT IN task.rejectedWorkerSids.
So, in order to filter by a rejectedWorkers attribute you need to maintain one yourself, by updating the task before you reject the reservation.
Let me know if that helps at all.

Azure Scheduled WebJob Never Finished Status

I have a scheduled web job that runs a function every minute:
[TimerTrigger("00:01:00", RunOnStartup = true)]
Sometimes it hangs and has a "Never Finish" status for a few days. This prevents new schedules for the job to be triggered. The Azure log also didn't record any entries - log was empty for that run.
I wonder if there is a way to tell Azure scheduler to continue with the scheduling if the job has a "Never Finish" status / state? Does setting "UseMonitor = true" do this?
As far as I know, if the scheduled web job processing is taking a long time periodically (or not finishing at all), it must be that every now and then the operations in your job function take a long time or fail. All depends on what your job is actually doing internally. If it is going async in places, the SDK will continue to wait for it to return.
According to this, I suggest you could try to use webjob's TimeoutAttribute.
It easy for functions to be cancelled based on timeout if they're hung.It will show a exception.
If you find the error is too much and you want to alter, I suggest you could use ErrorTrigger, you could refer to this article.
More details, you could refer to below codes.
I used the queue to test it, the result is as same as TimerTrigger webjob.
//Change the function timeout value
[Timeout("00:00:03")]
public static void TimeoutJob(
[QueueTrigger("queue")] string message,
CancellationToken token,
TextWriter log)
{
Console.WriteLine("From function: Received a message: " + message);
Task task = new Task(new Action(() => /*here is your code*/ Thread.Sleep(5000)), token);
// this will cancel the task is the token is CancellationRequested and show the exception the task is cancel
task.Wait();
Console.WriteLine("From function: Cancelled: Yes");
}

How correctly cancel LoadAsync after some timeout

Consider that I am using thread, which reads data stream from network socket (Windows::Networking::Sockets::StreamSocket) with help of Windows::Storage::Streams::DataReader (m_reader). I need to stop this thread and it waits mostly in LoadAsync. How to correctly cancel LoadAsync method after some timeout?
auto t1 = create_task(m_reader->LoadAsync(sizeof(len)));
t1.wait();
I tried several ways but none worked correctly. Or I can't use DataReader and I must choose some other approach?
Your call t1.wait(); is a blocking call that will throw an exception if the LoadAsync call fails for some reason. In your case, that HRESULT is ERROR_OPERATION_ABORTED, which is pretty much what I would expect ("The I/O operation has been aborted because of either a thread exit or an application request.")
What you could do is create a task cancellation token, attach it to your task, and then fire the token cancellation when desired.
From https://technet.microsoft.com/en-us/office/hh780559:
//Class member:
cancellation_token_source m_fileTaskTokenSource;
// Cancel button event handler:
m_fileTaskTokenSource.cancel();
// task chain
auto getFileTask2 =
create_task(documentsFolder->GetFileAsync(fileName),
m_fileTaskTokenSource.get_token());
Note: calling cancel on the cancellation token will cause the the task to throw a task_canceled exception, so you will need to catch and handle that exception.

Returning timer job status from custom timer job

There is a timer job status page in Central Admin
/_admin/ServiceRunningJobs.aspx
How can I properly return the status for my custom timer job ?
The Execute() method of timer job returns void.
It either fails (Exception) or succeeds (Method completes)
SPJobDefinition.UpdateProgress

Resources