Celery task display name - celery

I have some Celery tasks and I'm checking their states periodically from a separate process by instantiating an AsyncResult using the task id.
From this, I get the task state. By implementing a custom results backend and extended AsyncResult class as described here, I'm able to also get the task name too. However, I want able to get a custom display name for each task - something human readable so that I can display the state info in a user friendly way.
Hypothetically, it might be set something like:
#app.task()
def my_task(args):
display_name = "My Task"
...
...
Then later I would do...
result = ExtendedAsyncResult(task_id)
result.display_name
But from looking at the custom results backend I linked to, there doesn't appear to be any way to access the local variables of the task.
Is there a way to achieve what I'm looking for?

Celery support task name - hope this is what you are looking for:
#app.task(name='My Task')
def my_task(args):
...
...
the My Task will now appear wherever you want (in flower for example).

Related

CloudWatch Alarm via PowerShell - issue with InstanceName

I want to create CloudWatch alarms automatically on instance launch (via AutoScaling, CLI or whatever).
My instances are running Windows, so I created task in Task Scheduler which executes PowerShell script.
This script uses Write-CWMetricAlarm cmdlet to create CloudWatch Alarms - http://prntscr.com/e6xptj
It works good for custom Metrics like Windows/Default , but for AWS/EC2 Instance­Name is required as well - http://prntscr.com/e6xq18
But there's no Dimension for Instance­Name - http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html
.. as well as no suitable parameter for Write-CWMetricAlarm Cmdlet - http://docs.aws.amazon.com/powershell/latest/reference/Index.html
So any ideas about how this issue can be solved?
Thanks in advance!
Instance names are actually just tags (with key "Name") and the console gives them special treatment to make them appear as a first-class item. They also do not need to be unique, so using 'name' wouldn't enable CloudWatch to distinguish between different instances, making things confusing from an alarm perspective.
I think therefore that you need to be using the instance id value. In your script I notice you're using Invoke-Restmethod to obtain it - you might be interested to know you can also get this value using a cmdlet:
Get-EC2InstanceMetadata -Category InstanceId

Alfresco/Activiti multi-instance task variable use

I have an Activiti workflow that creates multiple (parallel) user tasks for an authorisation task (assigns each one to a group based on one element of a list).
<userTask id="authReview" name="Authorisation Review" activiti:candidateGroups="${assignee}" activiti:formKey="rowf:authReviewTask">
<documentation>
${assignee} Data Access request for approval.
</documentation>
<!-- One instance of this user task for each group that needs to authorise the request -->
<multiInstanceLoopCharacteristics isSequential="false"
activiti:collection="${rowf_reviewers}" activiti:elementVariable="assignee" >
</multiInstanceLoopCharacteristics>
</userTask>
As the ${assignee} variable is used to allocate the task to the correct group (after being read from the ${rowf_reviewers} list, is there any way to use ${assignee} to add to the task description?
The task description is currently set by the tag which seems to work fine but nothing is read from ${assignee}. I think this may be to do with a timing issue with the population of ${assignee} as "may" be populated before the gets evaluated.
Any assistance on how to get ${assignee} into the description would be appreciated.
I think what you are asking is if you can update the task description to include the assignee.
You can do this easily in a task listener on the "create" event.
Using the task Delegate (DelegateTask), simply call the setDescription method.
Let me know if I have misundersrood your need.
Greg
I have prepared simple jUnit test which works:
github jUnit test
I hope it helps.
Regards
Martin

Get NodeRef of a workflow task Alfresco

I create a workflow, and when I go to the task-edit page:
I'm trying to obtain the nodeRef of the file (latexexemplo-2.pdf) of the workflow task:
http://localhost:8080/share/page/task-edit?taskId=activiti$20649
I'm trying to make this way:
var taskId = args.taskId
var task = workflow.getTaskById(taskId);
nodeRef = task.getPackageResources()[0].nodeRef;
But I obtain "args is not defined" ... "workflow is not defined" ... "task is not defined".
How can I get the nodeRef with another way?
Unfortunately, you cannot access in the browser information that is in the repository.
A quick and dirty solution is to use directly the information that is already in the page.
I have started a workflow and opened the task page as you did.
Using the browser debug tool, I have inspected the html.
As you can see in the image attached below, Alfresco stores the documents attached to the task in an hidden input. You could use YAHOO to get it.
Search for an element with the id "page_x002e_data-form_x002e_task-edit_x0023_default_assoc_packageItems".
If there is more than one document associated, the value will be a comma separated list of noderefs. I am getting the first element. This of course works, as is, only if there is one and only one document associated. You should probably take into account also the case when no document is associated or there is more than one.
var nodeRef = YAHOO.util.Selector.query("#page_x002e_data-form_x002e_task-edit_x0023_default_assoc_packageItems")[0].value;
You can get all the current task details which are assigned to you by using
Workflow API in Freemarker.
So you can get the task id or noderef of tasks.

Alfresco: How to see the data of a finished task in the next task?

I need pass data of a task1 (form of task1) to other task (form of task2), and see this data in the form of task2. I use one aspect for this and I have the next code (a part) for the taskListener (event: complete) in task1:
execution.setVariable('wf_data1', task.getVariable('wf_data1'));
In my task2, in the share-config-custom.xml, I have the wf_data1 in the form, but this shows empty.
Why happen this? How to see the wf_data1 in task2?
UPDATE:
The reason of why this not working is which in the file service-context.xml, the redeploy key is "false". I changed this to "true" and all is working.
Greetings,
Arak.
I'm not going to dive into your model and ways of showing it. Alfresco keeps track of the workflow history. I'm not sure till what detail(with/without aspects) is available, but it's quite easy to find out.
With this you can access workflow data in a next task. Just create a custom workflow form controller which retrieves data.

How to get a person assigned to the task in Alfresco?

There are many elements in repo and I start workflows specifying a document attached to the workflow:
var workflow = actions.create("start-workflow");
// ...
var node = search.findNode("workspace://SpacesStore/" + uuid);
workflow.execute(node);
Workflow starts so I can see it in my-tasks page.
Then I want to receive an active task from the workflow and a list of people who works due to this task. Is it possible? Moreover I want to get a list of people assigned to the workflow at all.
But this is not all! I want to receive custom properties defined in the workflow model, but I don't see anything like properties field or methods to get property in the WorkflowInstance.
I'm sure that I just don't undestand something, so explain me please: how can I do everything I asked?