Created
July 18, 2010 10:34
-
-
Save aishfenton/480300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACCOUNT_ID = 2 | |
NUMBER_OF_JOBS = 1_000 | |
class PopulateJobs | |
def create_job(index) | |
job = @account.intervals.new(:name => "Job #{index}") | |
location = Location.new(:formatted_address => "12 Heather Street, Auckland, Parnell, New Zealand", :lat => 123.2342, :lng => 37.234232) | |
job.milestones.build({:location => location, :milestone_type => "Start", :sequence_order => 0, :planned_duration => 0}) | |
job.milestones.build({:location => location, :milestone_type => "End", :sequence_order => 1, :planned_duration => 3600}) | |
job[:ephemera] = {} | |
custom_fields = {} | |
5.times do |i| | |
cf_id = "cf_" + i.to_s | |
custom_fields[cf_id] = { | |
"label" => "my field #{i}", | |
"sequence_id" => i.to_s, | |
"type" => "object", | |
"mobile" => {"type"=>"free_text"}, | |
"field_type" => "text" | |
} | |
job[:ephemera][cf_id.to_sym] = "my value #{i}" | |
end | |
job.custom_fields = custom_fields | |
job.save! | |
job.allocate!(:allocated, @account.resources.first.id, Time.now, @account.users.first.id) | |
job.assign! | |
end | |
def populate(account_id, number) | |
@account = Account.find(account_id) | |
number.times do |i| | |
puts i.to_s | |
create_job(i) | |
end | |
end | |
end | |
PopulateJobs.new.populate(ACCOUNT_ID, NUMBER_OF_JOBS) | |
# ./script/runner populate_jobs.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment