Skip to content

Commit

Permalink
Merge pull request #39290 from code-dot-org/dtl_candidate_74fc592e
Browse files Browse the repository at this point in the history
  • Loading branch information
deploy-code-org committed Mar 1, 2021
2 parents 459c7df + 74fc592 commit 920d07a
Show file tree
Hide file tree
Showing 9 changed files with 685 additions and 56 deletions.
11 changes: 6 additions & 5 deletions bin/cron/hoc_student_name_cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ while date < options[:end_date]
batch_start_id = 0
batch_end_time = (date + 1).to_time
batch_number = 0
batch_rows_updated = 0

while batch_start_time < batch_end_time
ids_to_cleanup = []
Expand Down Expand Up @@ -189,6 +188,7 @@ while date < options[:end_date]
break if last_row.nil?

# Wrap the update in a transaction so we can rollback the changes on a dry run
batch_rows_updated = 0
DB.transaction do
batch_rows_updated = HOC_ACTIVITY.where(id: ids_to_cleanup).update(name: nil) unless ids_to_cleanup.empty?
raise Sequel::Rollback if options[:dry_run]
Expand All @@ -214,11 +214,12 @@ while date < options[:end_date]
end

# Send message to #cron-daily
summary = '*HoC Student Name Cleanup*\n'
summary += 'Dry-run (no changes written to database)\n' if options[:dry_run]
summary = "*HoC Student Name Cleanup*\n"
summary += "Dry-run (no changes written to database)\n" if options[:dry_run]
summary += "Script ran for #{(Time.now - script_start_time).round(1)} seconds. " \
"#{total_rows_processed} rows processed, #{total_rows_updated} rows updated.\n"
summary += "Script options: #{options}\n"
"#{total_rows_processed} rows processed, #{total_rows_updated} rows updated. " \
"Script options:\n"
summary += "```#{options}```"

ChatClient.message 'cron-daily', summary if options[:notify_slack]
CDO.log.info summary
17 changes: 2 additions & 15 deletions dashboard/app/controllers/script_levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,9 @@ def self.get_script_level(script, params)
if params[:chapter]
script.get_script_level_by_chapter(params[:chapter])
elsif params[:stage_position]
if (['csp2-2020', 'csp3-2020', 'csp4-2020', 'csp5-2020', 'csp6-2020', 'csp7-2020', 'csp9-2020', 'csp10-2020'].include? script.name) && script.lessons.last.absolute_position == params[:stage_position].to_i
script.get_script_level_by_absolute_position_and_puzzle_position(script.lessons.last.absolute_position, params[:id])
elsif script.name == 'csp1-2020' && script.lessons.last.absolute_position - 1 == params[:stage_position].to_i
script.get_script_level_by_absolute_position_and_puzzle_position(script.lessons.last.absolute_position, params[:id])
else
script.get_script_level_by_relative_position_and_puzzle_position(params[:stage_position], params[:id], false)
end
script.get_script_level_by_relative_position_and_puzzle_position(params[:stage_position], params[:id], false)
elsif params[:lockable_stage_position]
script.lessons.last.absolute_position
if (['csp2-2020', 'csp3-2020', 'csp4-2020', 'csp5-2020', 'csp6-2020', 'csp7-2020', 'csp9-2020', 'csp10-2020'].include? script.name) && 1 == params[:lockable_stage_position].to_i
script.get_script_level_by_absolute_position_and_puzzle_position(script.lessons.last.absolute_position, params[:id])
elsif script.name == 'csp1-2020' && 2 == params[:lockable_stage_position].to_i
script.get_script_level_by_absolute_position_and_puzzle_position(script.lessons.last.absolute_position, params[:id])
else
script.get_script_level_by_relative_position_and_puzzle_position(params[:lockable_stage_position], params[:id], true)
end
script.get_script_level_by_relative_position_and_puzzle_position(params[:lockable_stage_position], params[:id], true)
else
script.get_script_level_by_id(params[:id])
end
Expand Down
16 changes: 1 addition & 15 deletions dashboard/app/helpers/levels_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,7 @@ module LevelsHelper
include AzureTextToSpeech

def build_script_level_path(script_level, params = {})
if (['csp1-2020', 'csp2-2020', 'csp3-2020', 'csp4-2020', 'csp5-2020', 'csp6-2020', 'csp7-2020', 'csp9-2020', 'csp10-2020'].include? script_level.script.name) && (script_level.script.lessons.last.id == script_level.lesson.id)
if script_level.script.name == 'csp1-2020'
if params[:puzzle_page]
"/s/#{script_level.script.name}/stage/#{script_level.lesson.absolute_position - 1}/puzzle/#{script_level.position}/page/#{params[:puzzle_page]}"
else
"/s/#{script_level.script.name}/stage/#{script_level.lesson.absolute_position - 1}/puzzle/#{script_level.position}"
end
else
if params[:puzzle_page]
"/s/#{script_level.script.name}/stage/#{script_level.lesson.absolute_position}/puzzle/#{script_level.position}/page/#{params[:puzzle_page]}"
else
"/s/#{script_level.script.name}/stage/#{script_level.lesson.absolute_position}/puzzle/#{script_level.position}"
end
end
elsif script_level.script.name == Script::HOC_NAME
if script_level.script.name == Script::HOC_NAME
hoc_chapter_path(script_level.chapter, params)
elsif script_level.script.name == Script::FLAPPY_NAME
flappy_chapter_path(script_level.chapter, params)
Expand Down
10 changes: 0 additions & 10 deletions dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -849,16 +849,6 @@ def self.beta?(name)
name == Script::EDIT_CODE_NAME || ScriptConstants.script_in_category?(:csf2_draft, name)
end

def get_script_level_by_absolute_position_and_puzzle_position(absolute_position, puzzle_position)
script_levels.find do |sl|
# make sure we are checking the native properties of the script level
# first, so we only have to load lesson if it's actually necessary.
sl.position == puzzle_position.to_i &&
!sl.bonus &&
sl.lesson.absolute_position == absolute_position.to_i
end
end

def get_script_level_by_id(script_level_id)
script_levels.find(id: script_level_id.to_i)
end
Expand Down
5 changes: 4 additions & 1 deletion dashboard/test/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ You can find the values for these settings in your saucelabs account settings (`
If you want to run tests on saucelabs against localhost you need to set up your tunnel:

1. Login to Saucelabs and download the [tunnel](https://app.saucelabs.com/tunnels)
2. Start the tunnel via `~/bin/sc/ -u $SAUCELABS_USERNAME -k SAUCELABS_ACCESS_KEY`. Notes: The link above has an example command line with your credentials that you can copy. `~/bin/sc/` should be replaced with the path that points to the tunnel software downloaded in step 1.
2. Start the tunnel via `bin/sc --user <saucelabs-username> --api-key <saucelabs-api-key>`
- Notes: The link above has an example command line with your credentials that you can copy.
- `bin/sc` should be replaced with the path that points to the tunnel software downloaded in step 1.
- The unique tunnel identifier `-i <tunnel-id>` included in that command can be safely ignored; if you leave it in, you'll also need to set the `tunnelIdentifier` option in the `sauce_capabilities` config. See [Using Sauce Connect Tunnel Identifiers](https://wiki.saucelabs.com/display/DOCS/Using+Sauce+Connect+Tunnel+Identifiers#UsingSauceConnectTunnelIdentifiers-TheBasicsofUsingTunnelIdentifiers) for more details.
3. In a separate terminal window, `./runner.rb -d localhost-studio.code.org:3000 <whatever other arguments you want>`

You can now watch your tests run at the [saucelabs dashboard](https://saucelabs.com/beta/dashboard/tests)
Expand Down
1 change: 1 addition & 0 deletions lib/cdo/trusted_proxies.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"58.254.138.128/26",
"120.253.245.192/27",
"54.239.192.0/19",
"18.64.0.0/14",
"120.52.12.64/26",
"99.84.0.0/16",
"130.176.192.0/19",
Expand Down

0 comments on commit 920d07a

Please sign in to comment.