Skip to content

Commit

Permalink
Merge pull request TheOdinProject#164 from TopOneOfTopOne/add-threadi…
Browse files Browse the repository at this point in the history
…ng-to-rake-task

Add threading to rake task
  • Loading branch information
KevinMulhern committed Jun 4, 2016
2 parents 45954fd + 960df80 commit 358a7fb
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions lib/tasks/curriculum.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace :curriculum do
response = github.repos.contents.get :path => lesson.url
# Decode the gibberish into a real file and render to html
decoded_file = Base64.decode64(response["content"])
if decoded_file

if decoded_file
snippet_end = decoded_file.index("\n")-1 || 03
if lesson.content == decoded_file
puts " ...No new content."
Expand All @@ -37,7 +37,7 @@ namespace :curriculum do
raise "Failed to add content to the lesson (tried to add `nil`)!"
end
end

puts "\nChecking for any nils or blanks in the database"
Lesson.all.each do |l|
print "."
Expand All @@ -48,5 +48,36 @@ namespace :curriculum do
puts "...so we're ALL DONE! Updated the curriculum."
end

desc "Using multi threading to grab content from https://github.com/TheOdinProject/curriculum"
task :update_content_dev => :environment do
puts "Retrieving content... \n"
github = Github.new do |g|
g.user = "theodinproject"
g.repo = "curriculum"
g.oauth_token = "#{ENV['GITHUB_API_TOKEN']}"
end

threads = []
Thread.abort_on_exception = true

Lesson.all.each do |lesson|
threads << Thread.new do
response = github.repos.contents.get :path => lesson.url

content = Base64.decode64(response["content"])

raise "no contents" if !content

if lesson.content == content
print "-"
else
lesson.content = content
lesson.save!
print "+"
end
end
end
threads.map(&:join)
puts "\nDone..."
end
end

0 comments on commit 358a7fb

Please sign in to comment.