Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DMP-4216: Allow inactive tasks to be run manually #2238

Merged
merged 21 commits into from
Nov 12, 2024
Merged

Conversation

Ben-Edwards-cgi
Copy link
Contributor

Links

Jira

Change description

Summary of Changes

Updated manual task execution to bypass enabled / disabled checks. Meaning the task will be executed when run manually even if the task is disabled in the database.

Highlights

  • New Method for Running Tasks:

    • A new method run(boolean isManualRun) was added to the AutomatedTask interface, allowing tasks to indicate whether they are running manually or automatically.
    • A default method run() was also added, which defaults to calling the new method with false (indicating an automated run).
  • Modifications in Implementations:

    • The AbstractLockableAutomatedTask class was updated to implement the new run(boolean isManualRun) method.
    • The AutomatedTaskRunner class now takes into account whether a task is being run manually or automatically, logging the type of execution.
  • Service Layer Updates:

    • The AdminAutomatedTasksServiceImpl class now triggers the automated task with the new manual run parameter set to true when tasks are run manually.
  • Test Adjustments:

    • Corresponding tests were updated to match the new method signatures and to ensure that the manual run functionality is tested appropriately.

These changes collectively improve the control and monitoring of automated tasks, making it easier for developers to distinguish between different execution modes.

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[X] No

@@ -71,8 +71,8 @@ void invokesTaskWhenTaskIsNotLocked() {

adminAutomatedTaskService.runAutomatedTask(1);

verify(automatedTaskRunner, times(1)).run(someAutomatedTask);
verify(auditApi, times(1)).record(AuditActivity.RUN_JOB_MANUALLY,"some-task-name");
verify(automatedTaskRunner, times(1)).run(someAutomatedTask, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have set isManual to true but is there a test where its set to false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the is manual run false should be covered by the existing tests for automated tasks. As when it is not manually run we default this value to be false

Copy link
Contributor

@davet1985 davet1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add an info log as described in the ticket

Add an info log entry to state that an inactive task has been run, such as "Task: {} is inactive but has been run manually"

@hmcts-jenkins-cnp hmcts-jenkins-cnp bot requested a deployment to preview November 7, 2024 21:02 Abandoned
@hmcts-jenkins-cnp hmcts-jenkins-cnp bot requested a deployment to preview November 11, 2024 10:11 Abandoned
@hmcts-jenkins-cnp hmcts-jenkins-cnp bot requested a deployment to preview November 11, 2024 13:19 Abandoned
@Ben-Edwards-cgi Ben-Edwards-cgi enabled auto-merge (squash) November 12, 2024 09:40
@@ -79,7 +79,7 @@ private void setupUserAuthentication() {
}

@Override
public void run() {
public void run(boolean isManualRun) {
Copy link
Contributor

@jackmaloney jackmaloney Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is making my head hurt. Why are we passing this isManualRun in as a parameter? Can't we just use the isManualTask variable that is already used in this class? Or just get rid of the isManualTask class variable and use your new parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the ManualTaskService as this no longer provided any value and updated the code to reflect this change

@@ -90,7 +90,10 @@ public void run() {
String dbCronExpression = automatedTask.getCronExpression();
// Check the cron expression hasn't been changed in the database by another instance, if so skip this run
if (isManualTask || getLastCronExpression().equals(dbCronExpression)) {
if (TRUE.equals(automatedTask.getTaskEnabled())) {
if (isManualRun || TRUE.equals(automatedTask.getTaskEnabled())) {
if (isManualRun && !TRUE.equals(automatedTask.getTaskEnabled())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need the isManualRun && part here. If the second part of the if statement is met, then it means you can only have got there if it was manually triggered, so it's redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed removed :)

@Ben-Edwards-cgi Ben-Edwards-cgi merged commit 5c0f772 into master Nov 12, 2024
10 checks passed
@Ben-Edwards-cgi Ben-Edwards-cgi deleted the DMP-4216 branch November 12, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants