How to revoke a task properly considering its state could happen to shift - mongodb

I'm developing the service for customer's orders monitoring, using MongoDB as the standalone backend for tracking and storage of celery tasks' state. So far, it works well, refreshing and displaying the state of all the tasks submitted by a current customer, e.g. STARTED, SUCCESS, FAILURE.
The monitoring UI could be some format as following.
+----------+--------------+-------------+--------------------+
|task_id |created_at |status |operation |
|----------|--------------|-------------|--------------------|
|[uuid] |[timestamp] |[STARTED] |[DOWNLOAD] [DELETE] |
|[uuid] |[timestamp] |[SUCCESS] |[DOWNLOAD] [DELETE] |
|[uuid] |[timestamp] |[RECEIVED] |[DOWNLOAD] [DELETE] |
|[uuid] |[timestamp] |[FAILURE] |[DOWNLOAD] [DELETE] |
|... |... |... |... |
+----------+--------------+-------------+--------------------+
Now I want to implement this [DELETE] utility, which means the customer could revoke a task being executed, via a HTTP request. Considering state of a task could happed to switch into a SUCCESSor FAILURE or other state if there's a latency of request due to HTTP overhead, is it proper to use app.control.revoke(task_id, terminate=True) ?
UPDATED:
Now I configure worker_state_db='/var/run/celery/worker.state.db' in config file of celery for persistent revokes, and stick to app.control.revoke(..., terminate=True). Is it a right option ? I did realize how this revoke command works when I found related answers here.
Which is the best way to programatically terminate (cancel) a celery task
Revoke a task from celery
Celery Task Custom tracking method
Because the service couldn't know target task state when revoke command being broadcasted, it could be as following.
scenario1: target task state is SUCCESS or FAILURE:
worker node is executing another new task (just say task aaa) when being revoked, and will restart executing task aaa. So I have to synchronize REVOKED status of target task into MongoDB without usage of task_revoked signal
scenario2: target task state is RECEIVED or STARTED or other :
worker node is executing this target task, and task_revoked signal would be triggered. But I failed to use this task_revoked signal to synchronize task status into MongoDB. Thus I tried to manually update MongoDB in the same way of scenario1 given a reply received from app.control.revoke(..., terminate=True, reply=True). But I still got a problem as following.
[# ERROR/MainProcess] Task handler raised error: Terminated(15)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/billiard/pool.py", line 1774, in _set_terminated
raise Terminated(-(signum or 0))
billiard.exceptions.Terminated: 15
How to solve this problem ? And please correct me if I still got something wrong.

I have it implemented the way you describe. There are a couple of things to note:
If you send the revoke command and the task is already done (either in SUCCESS or FAILURE status), the revoke command won't do anything and simply reply that it doesn't know the task. (And more importantly it also won't terminate the child worker process.) See the code for yourself.
You have to be cautious when using terminate=True, though. Depending on how you configure Celery, the worker that's executing your task might have already started another task when the revoke command is sent. There's an explicit warning in the documentation.
On the other hand, once the Celery worker starts to process your task and you really need to cancel the processing, revoking and killing the worker process is the only option.

Related

Force stop Azure App Service Deployment Slot Swap

We are using Azure DevOps to deploy to a staging slot and then swap with production.
When there is an issue swapping it will keep trying for nearly 30 minutes.
Therefore I would like to put a timeout on the swap task, but if I do that it will stop the task in DevOps and leave the process happening in Azure.
I would like a way to force stop the process through a CLI, API, PowerShell or DevOps task.
Azure CLI doesn't seem to have anything
Kudu API can delete deployments but doesn't look to stop them (https://github.com/projectkudu/kudu/wiki/REST-API#deployment)
I have read that you can stop a process, but using a Linux Container App Service, I can't see that option. Azure-Web-sites: How to cancel a deployment?
Is there a way?
Please try to use the following command in Azure PowerShell task to cancel a pending swap:
Invoke-AzResourceAction -ResourceGroupName [resource group name] -ResourceType Microsoft.Web/sites/slots -ResourceName [app name]/[slot name] -Action resetSlotConfig -ApiVersion 2015-07-01
Here is the document and my sample, I added -Force -Confirm:$false at the end of the command:
Update
If any errors occur in the target slot (for example, the production slot) after a slot swap, restore the slots to their pre-swap states by swapping the same two slots immediately.
So, we don't need to stop it, just wait swap operation succeed.
When you submit swap slot request, you will get HttpStatus 202 code. On portal, when you click swap button, you will find that the browser has been requesting the url of location to get the status of swap.
As for when it ends, we can check the swap operation by polling.
If the swap operation time is too long, it is recommended to raise a support ticket and ask the engineer to check the reason.
Previous
You can use AzureAppServiceManage task.
Azure App Service Manage task
Use this task to start, stop, restart, slot swap, Swap with Preview, install site extensions, or enable continuous monitoring for an Azure App Service.
Tips
When you use rest api to swap slot, you can check location in response header.
When you submit swap slot request, you will get HttpStatus 202 code. On portal, when you click swap button, you will find that the browser has been requesting the url of location to get the status of swap.

How to restart an exe when it is exits in windows 10?

I have a process in windows which i am running in startup. Now i need to make it if somehow that process get killed or stopped i need to restart it again in Windows 10?
Is there any way. Process is a HTTP server which if somehow stopped in windows i need to restart it. I have tried of writing a power-shell in which I'll check task-list status of process and then if not found I'll restart but that is not a good way. Please suggest some good way to do it.
I have a golang exe; under a particular scenario my process got killed or stopped i need to start it up again automatically. This has to be done imediately after the exe got killed. What is the best way to achieve this?
I will give you a brief rundown. You can enable Audit Process Termination in local group policy of the machine as shown below. In your case, success audits would be enough. Please note that the pic is for Windows 7. It may change with OS.
Now every time a process gets terminated, a success event will be generated and written to the security eventlog.
This will allow you to create a task scheduler that triggers on the generation of this event that calls a script that would run the process again. Simple right?
Well, you might have some trouble setting that task up especially when you want to pass details about the generating event to the script. This should help you get through that.
You can user Task scheduler for this purpose. There is a option of "restart on failure" which can be selected and whenever your process get failed it will restart again.
Reference :- https://social.technet.microsoft.com/Forums/windowsserver/en-US/4545361c-cc1f-4505-a0a1-c2dcc094109a/restarting-scheduled-task-that-has-failed?forum=winserverManagement

TAC (Talend Administration center) synchronisation problem with the job server ( job still showing "running" in tac though the job finished)

I have an issue that occurs in DI 6.2 with a job that stucks with the status "running" on TAC but when i verify directly in the job server i find that job finished executing,
I can't find the root cause for this issue, the logs on the server doesn't contain errors,
I think the communication between the TAC and the job server is broken!
This is actually a defect. Of course a reboot will solve the problem, but it requires a reboot whenever the problem reappears.
There is a patch available for TAC that should solve the problem. Please raise a Talend support ticket.
this could be caused by a restart of your TAC, which messed up job statuses.
You can check job status in EXECUTIONTASK table of your installation DB (if you don't know which DB it is, check Configuration>Database tab with an admin user in TAC). There you can update 'STATUS' field in this table for this job.

Timeout - Clone and Base table

Procedure of my mainframe job has a step which performs an exchange between clone and base table. This step fails every time the job runs with resource unavailable error. The resource is a package for another program which reads the base table used in my job.
Since the job is failing with timeout error, I usually restart this. But to fix this permanently, is it possible to increase the timeout limit for this EXCHANGE process. In IBM manual, I could see "SET CURRENT LOCK TIMEOUT 30" for this. But is this valid. My EXCHANGE statement between clone and base table is coded in a control card. Is there any possibility I can increase the timeout so that the job does not go into error.
If any further details is required, please let me know
Any help on this is appreciated.

moodle no change in status 'in progress'

I am facing problem with moodle configurations. I have 2 courses setup and the activity completion set for these courses are 1. manual self comletion and 2. Manual completion by manager.
I have also added required blocks for the same.
I completed the course successfully, marked completed by student as well as manager. In the status block it shows block image
Need help to get the status showing complete. I dont know what exactly i am missing.
You should start the Moodle cron tasks in order to update the completion status.
You can manually start the tasks either by running (only if you are an admin) a command from your browser:
http://your.site/admin/cron.php
or by running a command line in you system (from a terminal), like:
/path/to/your/moodle/installation/admin/cli/cron.php
A list of predefined cron tasks of you system can be found under:
http://your.site/admin/tool/task/scheduledtasks.php
or going under Site administration->Server->Scheduled tasks