mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
namespace :init do
|
|
desc 'create some example posts data'
|
|
task :create_posts => :environment do
|
|
do_task_with_counting_time do
|
|
@user = User.first
|
|
|
|
def create_post(description, type, url)
|
|
post = Post.find_or_create_by!(url: url, type: type)
|
|
@user.share_instances.create! sharable: post, description: description
|
|
ProcessPostWorker.perform_async url
|
|
end
|
|
|
|
url_1 = 'http://www.cnbeta.com/articles/424731.htm'
|
|
type_1 = 'Article'
|
|
description_1 = '迪士尼电影《怪兽电力公司》及《怪兽大学》自上映后便受到了很多影迷的热捧'
|
|
create_post(description_1, type_1, url_1)
|
|
|
|
url_2 = 'https://github.com/git-up/GitUp'
|
|
type_2 = 'WebPage'
|
|
description_2 = "The Git interface you've been missing all your life has finally arrived."
|
|
create_post(description_2, type_2, url_2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def do_task_with_counting_time
|
|
print "[INFO]: staring doing migration.\n"
|
|
start_time = Time.now
|
|
yield
|
|
end_time = Time.now
|
|
print "[INFO]: migration finished in #{end_time- start_time}s.\n"
|
|
end
|
|
end
|