Ich habe eine Haupt-Rake-Aufgabe setup_a_new_set_of_snippets.rake
, die ich anrufe, die dann andere Aufgaben anruft. So sieht die wichtigste wie folgt aus:Warum wird diese Rake-Aufgabe zweimal ausgeführt?
load './lib/tasks/fetch_and_create_snippets.rake'
load './lib/tasks/generate_diffs_for_snippets.rake'
load './lib/tasks/cleanup_snippets_with_empty_diffs.rake'
desc "Setup a new set of Snippets"
task :setup_a_new_set_of_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
repo = args[:repo]
path = args[:path]
entry_id = args[:entry_id]
framework_id = args[:framework_id]
method_name = args[:method_name]
Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)
Rake::Task["generate_diffs_for_snippets"].invoke
Rake::Task["cleanup_snippets_with_empty_diffs"].invoke(framework_id)
end
Aus irgendeinem Grund die fetch_and_create_snippets
Harke, die wie folgt ausgeführt wird: Rake::Task["fetch_and_create_snippets"].invoke(repo,path,entry_id,framework_id,method_name)
scheint zweimal ausgeführt werden.
Hier ist diese Aufgabe - fetch_and_create_snippets.rake
:
desc 'Fetch and Create Snippets from Github'
task :fetch_and_create_snippets, [:repo, :path, :entry_id, :framework_id, :method_name] => :environment do |task, args|
repo = args[:repo]
path = args[:path]
entry_id = args[:entry_id]
framework_id = args[:framework_id]
method_name = args[:method_name]
client = Octokit.client
commits = GetCommits.new(repo, path).all
commits_count = commits.count
commits.each_with_index do |commit, index|
content = client.contents(repo, path: path, ref: commit.sha)
if Snippet.exists?(gh_sha: content.sha)
puts "#{index}/#{commits_count} - EXISTS - #{commit.commit.author.email} - #{content.sha}".blue
elsif commit.author.nil?
puts "#{index}/#{commits_count} - NO AUTHOR - #{commit.commit.author.email} - #{content.sha}".magenta
else
create_snippet = CreateSnippet.new(repo, path, entry_id, framework_id, commit, method_name)
if create_snippet
puts "#{index}/#{commits_count} - #{commit.author.login} - #{commit.sha} SUCCESSFULLY CREATED".green
else
puts "#{index}/#{commits_count} - #{commit.author.login} - #{commit.sha} - NOT SUCCESSFULLY CREATED - #{create_snippet.errors}".red
end
end
end
end
Dies ist, was an der Konsole die Ausgabe wie folgt aussieht:
erste Charge erfolgreich ausgeführt Ereignisse aus dem ersten Lauf von fetch_and_create_snippets
:
783/786 - dhh - ac3c8a54f83418b5cac4b093fc1bae29f59f3a1f SUCCESSFULLY CREATED
Snippet ID: 2974 SUCCESSFULLY SANITIZED
784/786 - dhh - 7022dd9c05064ef914f8836fb5e8b2d2ee3c02ed SUCCESSFULLY CREATED
Snippet ID: 2975 SUCCESSFULLY SANITIZED
785/786 - dhh - db045dbbf60b53dbe013ef25554fd013baf88134 SUCCESSFULLY CREATED
Dann wird es erneut ausgeführt und zeigt die EXISTS
Ausgabe, die nur ausgibt, sobald das Snippet existiert.
0/786 - EXISTS - [email protected] - c91b5d3fe3d263963eb3f9ef2ec0dc0074951064
1/786 - EXISTS - [email protected] - 3729e22e6423348aa9282cd17b49c09793ca3a6f
2/786 - EXISTS - [email protected] - ec9b073c185dcef26bd3293ac124fee8285de103
3/786 - EXISTS - [email protected] - 5a973fa8019962133449c073c4e8b5cf2ce8fb36
4/786 - EXISTS - [email protected] - fe440fccc7398d2cd0b4f04f700c62cc76ba2b0a
5/786 - EXISTS - [email protected] - 2fbecb7d0447b70b30b71addfbc97608690b4106
6/786 - EXISTS - [email protected] - 77d17fc9757bcbbc63267c2e408b4dbe8ab5d930
7/786 - EXISTS - [email protected] - ef35d80523fd066ae1d836658ef840dd0da93849
8/786 - EXISTS - [email protected] - e13fe33b857c7f608590bf80030f8c837a15faea
9/786 - EXISTS - [email protected] - 03c8b4c97be4ffaf1f84daf657915d8953219476
Und das läuft durch die gleiche Charge es das erste Mal.
Was könnte diesen Doppellauf verursachen?