Skip to content

Commit

Permalink
Removes unwanted suggestion cron jobs (oppia#10423)
Browse files Browse the repository at this point in the history
  • Loading branch information
DubeySandeep authored Aug 24, 2020
1 parent bdf758f commit 0bec24e
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 86 deletions.
21 changes: 1 addition & 20 deletions core/controllers/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
from core.domain import cron_services
from core.domain import email_manager
from core.domain import recommendations_jobs_one_off
from core.domain import suggestion_services
from core.domain import user_jobs_one_off
from core.domain import wipeout_jobs_one_off
from core.platform import models
import feconf
import utils

from pipeline import pipeline

(job_models, suggestion_models) = models.Registry.import_models([
models.NAMES.job, models.NAMES.suggestion])
(job_models,) = models.Registry.import_models([models.NAMES.job])

# The default retention time is 2 days.
MAX_MAPREDUCE_METADATA_RETENTION_MSECS = 2 * 24 * 60 * 60 * 1000
Expand Down Expand Up @@ -216,19 +213,3 @@ def get(self):
jobs.MAPPER_PARAM_MAX_START_TIME_MSEC: max_start_time_msec
})
logging.warning('Deletion jobs for auxiliary entities kicked off.')


class CronAcceptStaleSuggestionsHandler(base.BaseHandler):
"""Handler to accept suggestions that have no activity on them for
THRESHOLD_TIME_BEFORE_ACCEPT time.
"""

@acl_decorators.can_perform_cron_tasks
def get(self):
"""Handles get requests."""
if feconf.ENABLE_AUTO_ACCEPT_OF_SUGGESTIONS:
suggestions = suggestion_services.get_all_stale_suggestions()
for suggestion in suggestions:
suggestion_services.accept_suggestion(
suggestion, feconf.SUGGESTION_BOT_USER_ID,
suggestion_models.DEFAULT_SUGGESTION_ACCEPT_MESSAGE, None)
54 changes: 0 additions & 54 deletions core/controllers/cron_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
from core.controllers import cron
from core.domain import cron_services
from core.domain import email_manager
from core.domain import exp_fetchers
from core.domain import state_domain
from core.domain import suggestion_services
from core.platform import models
from core.platform.taskqueue import gae_taskqueue_services as taskqueue_services
from core.tests import test_utils
import feconf
import main_cron

from mapreduce import model as mapreduce_model
Expand Down Expand Up @@ -280,53 +276,3 @@ def _mock_logging_function(msg, *args):
'A previous cleanup job is still running.'
]
)

def test_cron_accept_stale_suggestions_handler(self):
self.login(self.ADMIN_EMAIL, is_super_admin=True)
self.save_new_valid_exploration(
'exp_id', self.admin_id, title='A title', category='Algebra')
author_id = self.get_user_id_from_email(self.ADMIN_EMAIL)

new_content = state_domain.SubtitledHtml(
'content', '<p>new suggestion content</p>').to_dict()
change = {
'cmd': 'edit_state_property',
'property_name': 'content',
'state_name': 'Introduction',
'new_value': new_content
}
suggestion_services.create_suggestion(
suggestion_models.SUGGESTION_TYPE_EDIT_STATE_CONTENT,
suggestion_models.TARGET_TYPE_EXPLORATION,
'exp_id', 1,
author_id, change, 'change title')

exploration = exp_fetchers.get_exploration_by_id('exp_id')
self.assertEqual(
exploration.states['Introduction'].content.to_dict(), {
'content_id': 'content',
'html': ''
}
)

threshold_time_before_accept_swap = self.swap(
suggestion_models, 'THRESHOLD_TIME_BEFORE_ACCEPT_IN_MSECS', 0)
auto_accept_suggestions_swap = self.swap(
feconf, 'ENABLE_AUTO_ACCEPT_OF_SUGGESTIONS', True)

with threshold_time_before_accept_swap, self.testapp_swap, (
auto_accept_suggestions_swap):
self.assertEqual(
len(suggestion_services.get_all_stale_suggestions()), 1)
self.get_html_response('/cron/suggestions/accept_stale_suggestions')

self.assertEqual(
len(suggestion_services.get_all_stale_suggestions()), 0)

exploration = exp_fetchers.get_exploration_by_id('exp_id')
self.assertEqual(
exploration.states['Introduction'].content.to_dict(), {
'content_id': 'content',
'html': '<p>new suggestion content</p>'
}
)
6 changes: 0 additions & 6 deletions cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ cron:
- description: weekly exploration search rank computation
url: /cron/explorations/search_rank
schedule: every wednesday 9:00
- description: accept all stale suggestions every week
url: /cron/suggestions/accept_stale_suggestions
schedule: every thursday 9:00
- description: notify reviewers about suggestions requiring review
url: /cron/suggestions/notify_reviewers
schedule: every day 9:00
- description: "Weekly Cloud Datastore Export"
url: /cloud_datastore_export?namespace_id=&output_url_prefix=gs://oppia-export-backups
target: cloud-datastore-admin
Expand Down
3 changes: 0 additions & 3 deletions feconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ def get_empty_ratings():
# Maximum allowed commit message length for SnapshotMetadata models.
MAX_COMMIT_MESSAGE_LENGTH = 1000

# Whether to automatically accept suggestions after a threshold time.
ENABLE_AUTO_ACCEPT_OF_SUGGESTIONS = False

EMAIL_INTENT_SIGNUP = 'signup'
EMAIL_INTENT_DAILY_BATCH = 'daily_batch'
EMAIL_INTENT_EDITOR_ROLE_NOTIFICATION = 'editor_role_notification'
Expand Down
3 changes: 0 additions & 3 deletions main_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
cron.CronActivitySearchRankHandler),
main.get_redirect_route(
r'/cron/jobs/cleanup', cron.CronMapreduceCleanupHandler),
main.get_redirect_route(
r'/cron/suggestions/accept_stale_suggestions',
cron.CronAcceptStaleSuggestionsHandler),
]

app = transaction_services.toplevel_wrapper( # pylint: disable=invalid-name
Expand Down

0 comments on commit 0bec24e

Please sign in to comment.