Async Tasks Run Once - quality-manager/onboarding GitHub Wiki

Background

Often there is a need to run a task once or programmatically turn off a task after the completion of some type of job. For example, a migration type of task.

Example

The following is a pattern which could be used to stop a task from running by setting the advanced properties for the task.

	protected void setServerConfigTaskDelayToNotRun() throws TeamRepositoryException {
        JSONObject jsonUpdate = new JSONObject();
        jsonUpdate.put("serviceImplementationName", this.getClass().getName());
        jsonUpdate.put("name", "AttachmentMigrationTask.fixedDelay");
        jsonUpdate.put("value", "-1");
        JSONArray jsonUpdates = new JSONArray();
        jsonUpdates.add(jsonUpdate);
        IServerConfigurationRestService.ParamsConfigurationUpdates params = new IServerConfigurationRestService.ParamsConfigurationUpdates();
        params.updates = jsonUpdates.toString();
        getService(IServerConfigurationRestService.class).postConfigurationUpdates(params);
    }