-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Create task that destroys removed activities #5095
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the code looks good, does this need a test? Or it might be too much work to properly test, I don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code and criteria look good, but I have two remarks.
Right now, from the code, it isn't clear what the side effects will be: if a draft exercise was added to a series, will it be removed from the series? If it has submissions, will those be removed? Maybe add this in comments.
Running this as a cronjob is ok, but we don't have any other tasks like this right now. We should therefore discuss if this is the best way to run this. An alternative is using delayed job and a function that schedules itself as a last step of its execution.
if activity.draft? || activity.series_memberships.empty? | ||
# destroy series memberships first explicitly, as they are dependent: :restrict_with_error | ||
activity.series_memberships.destroy_all | ||
|
||
activity.destroy | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work if the content page has been marked as read? And if so, do we want it to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works with activity_read_states (see the first test)
We could also add a limit of at most 25 activity_read_states, but as a lot less information is lost in the case of the activity_read_states compared to submissions, I did not care about it
end | ||
|
||
# rerun this job in 1 month | ||
RemoveActivitiesJob.set(wait: 1.month).perform_later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also delayed_cron_job that takes care of this, but we might not want to introduce a dependency to replace one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no preference, do you want me to replace this functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave the code as-is for now. If we add more similar tasks later, we can always add the gem.
This pull request adds an active job that permanently destroys removed activities that match all of the following criteria:
This job should be started once and reschedules itself every month.
Some relevant stats from naos:
Closes #4969 and #4764