phocoder-rails 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/VERSION +1 -1
- data/app/models/encodable_job.rb +125 -13
- data/lib/generators/phocoder_rails/templates/migration.rb +3 -1
- data/lib/phocoder_rails/acts_as_phocodable.rb +133 -43
- data/spec/controllers/phocoder_controller_spec.rb +30 -1
- data/spec/dummy/db/migrate/20110523165522_create_encodable_jobs.rb +2 -1
- data/spec/dummy/db/migrate/20121230165930_add_tracking_mode_to_encodable_jobs.rb +5 -0
- data/spec/dummy/db/schema.rb +2 -1
- data/spec/models/acts_as_phocodable_spec.rb +55 -0
- data/spec/models/encodable_job_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +4 -3
data/Gemfile
CHANGED
data/VERSION
CHANGED
data/app/models/encodable_job.rb
CHANGED
@@ -3,6 +3,13 @@ class EncodableJob < ActiveRecord::Base
|
|
3
3
|
belongs_to :encodable, :polymorphic=>true
|
4
4
|
|
5
5
|
scope :pending, :conditions => "phocoder_status != 'ready'"
|
6
|
+
scope :for_components, :conditions => "tracking_mode = 'component'"
|
7
|
+
scope :for_jobs, :conditions => "tracking_mode = 'job'"
|
8
|
+
|
9
|
+
def initialize(params = {}, options={})
|
10
|
+
super
|
11
|
+
self.tracking_mode = "component" unless self.tracking_mode
|
12
|
+
end
|
6
13
|
|
7
14
|
def update_status
|
8
15
|
job_data = Phocoder::Job.details(phocoder_job_id).body
|
@@ -61,7 +68,101 @@ class EncodableJob < ActiveRecord::Base
|
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
71
|
+
|
64
72
|
def self.update_from_phocoder(params)
|
73
|
+
if params[:outputs] && params[:inputs]
|
74
|
+
update_from_phocoder_job_style(params)
|
75
|
+
else
|
76
|
+
update_from_phocoder_component_style(params)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.update_from_phocoder_job_style(params)
|
81
|
+
if params[:job][:type] == 'ThumbnailJob'
|
82
|
+
update_from_phocoder_thumbnail_job(params)
|
83
|
+
elsif params[:job][:type] == 'CompositeJob' || params[:job][:type] == 'ToneMappingJob'
|
84
|
+
update_from_phocoder_generic_job_with_thumbnails(params)
|
85
|
+
else
|
86
|
+
update_from_phocoder_generic_job(params)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.update_from_phocoder_thumbnail_job(params)
|
91
|
+
#debugger
|
92
|
+
job = self.for_jobs.find_by_phocoder_job_id params[:job][:id]
|
93
|
+
encodable = job.encodable
|
94
|
+
|
95
|
+
img_params = params[:inputs].first
|
96
|
+
update_encodable_and_job_from_img_params(encodable,job,img_params)
|
97
|
+
|
98
|
+
params[:outputs].each do |thumb_params|
|
99
|
+
thumbnail = encodable.thumbnail_for(thumb_params[:label])
|
100
|
+
update_encodable_and_job_from_img_params(thumbnail,job,thumb_params)
|
101
|
+
thumbnail.encodable_status = "ready" if thumbnail.respond_to?(:encodable_status=)
|
102
|
+
thumbnail.phocoder_status = "ready" if thumbnail.respond_to?(:phocoder_status=)
|
103
|
+
thumbnail.save!
|
104
|
+
end
|
105
|
+
|
106
|
+
encodable.encodable_status = "ready" if encodable.respond_to?(:encodable_status=)
|
107
|
+
encodable.phocoder_status = "ready" if encodable.respond_to?(:phocoder_status=)
|
108
|
+
encodable.save!
|
109
|
+
encodable.fire_ready_callback
|
110
|
+
|
111
|
+
job.phocoder_status = "ready"
|
112
|
+
job.save
|
113
|
+
job
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.update_from_phocoder_generic_job(params)
|
117
|
+
#debugger
|
118
|
+
job = self.for_jobs.find_by_phocoder_job_id params[:job][:id]
|
119
|
+
encodable = job.encodable
|
120
|
+
|
121
|
+
img_params = params[:outputs].first
|
122
|
+
update_encodable_and_job_from_img_params(encodable,job,img_params)
|
123
|
+
|
124
|
+
encodable.encodable_status = "ready" if encodable.respond_to?(:encodable_status=)
|
125
|
+
encodable.phocoder_status = "ready" if encodable.respond_to?(:phocoder_status=)
|
126
|
+
encodable.save!
|
127
|
+
encodable.fire_ready_callback
|
128
|
+
|
129
|
+
job.phocoder_status = "ready"
|
130
|
+
job.save
|
131
|
+
job
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.update_from_phocoder_generic_job_with_thumbnails(params)
|
135
|
+
#debugger
|
136
|
+
job = self.for_jobs.find_by_phocoder_job_id params[:job][:id]
|
137
|
+
encodable = job.encodable
|
138
|
+
|
139
|
+
img_params = {}
|
140
|
+
|
141
|
+
|
142
|
+
params[:outputs].each do |thumb_params|
|
143
|
+
if thumb_params[:label].blank?
|
144
|
+
img_params = thumb_params
|
145
|
+
next
|
146
|
+
end
|
147
|
+
thumbnail = encodable.thumbnail_for(thumb_params[:label])
|
148
|
+
update_encodable_and_job_from_img_params(thumbnail,job,thumb_params)
|
149
|
+
thumbnail.encodable_status = "ready" if thumbnail.respond_to?(:encodable_status=)
|
150
|
+
thumbnail.phocoder_status = "ready" if thumbnail.respond_to?(:phocoder_status=)
|
151
|
+
thumbnail.save!
|
152
|
+
end
|
153
|
+
|
154
|
+
update_encodable_and_job_from_img_params(encodable,job,img_params)
|
155
|
+
encodable.encodable_status = "ready" if encodable.respond_to?(:encodable_status=)
|
156
|
+
encodable.phocoder_status = "ready" if encodable.respond_to?(:phocoder_status=)
|
157
|
+
encodable.save!
|
158
|
+
encodable.fire_ready_callback
|
159
|
+
|
160
|
+
job.phocoder_status = "ready"
|
161
|
+
job.save
|
162
|
+
job
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.update_from_phocoder_component_style(params)
|
65
166
|
Rails.logger.debug "tying to call update from phocoder for params = #{params.to_json}"
|
66
167
|
puts "tying to call update from phocoder for params = #{params.to_json}"
|
67
168
|
if !params[:output].blank?
|
@@ -92,24 +193,21 @@ class EncodableJob < ActiveRecord::Base
|
|
92
193
|
img_params = params[:input]
|
93
194
|
encodable = job.encodable
|
94
195
|
end
|
95
|
-
|
96
|
-
|
97
|
-
:focal_length, :focal_length_in_35mm_film, :subsec_time, :pixels, :processing_time].each do |att|
|
98
|
-
setter = att.to_s + "="
|
99
|
-
if encodable.respond_to? setter and !img_params[att].blank?
|
100
|
-
encodable.send setter, img_params[att]
|
101
|
-
end
|
102
|
-
if job.respond_to? setter and !img_params[att].blank?
|
103
|
-
job.send setter, img_params[att]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
196
|
+
|
197
|
+
update_encodable_and_job_from_img_params(encodable,job,img_params)
|
107
198
|
#job.file_size = img_params[:file_size]
|
108
199
|
#job.width = img_params[:width]
|
109
200
|
#job.height = img_params[:height]
|
110
201
|
encodable.encodable_status = "ready"
|
202
|
+
|
111
203
|
encodable.save
|
112
|
-
|
204
|
+
|
205
|
+
if params[:output].blank? && params[:input].blank?
|
206
|
+
# Do nothing? Only for tracking job status, not components...
|
207
|
+
else
|
208
|
+
encodable.fire_ready_callback
|
209
|
+
end
|
210
|
+
|
113
211
|
# may not have a job if the EncodableJob didn't get created for some reason
|
114
212
|
if job
|
115
213
|
job.phocoder_status = "ready"
|
@@ -118,6 +216,20 @@ class EncodableJob < ActiveRecord::Base
|
|
118
216
|
end
|
119
217
|
end
|
120
218
|
|
219
|
+
|
220
|
+
def self.update_encodable_and_job_from_img_params(encodable,job,img_params)
|
221
|
+
[ :file_size,:width,:height,:taken_at,:lat,:lng,:saturated_pixels,:gauss,:bits_per_pixel,:camera_make,
|
222
|
+
:camera_model, :orientation, :exposure_time, :f_number, :iso_speed_rating, :exposure_bias_value,
|
223
|
+
:focal_length, :focal_length_in_35mm_film, :subsec_time, :pixels, :processing_time].each do |att|
|
224
|
+
setter = att.to_s + "="
|
225
|
+
if encodable.respond_to? setter and !img_params[att].blank?
|
226
|
+
encodable.send setter, img_params[att]
|
227
|
+
end
|
228
|
+
if job.respond_to? setter and !img_params[att].blank?
|
229
|
+
job.send setter, img_params[att]
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
121
233
|
|
122
234
|
|
123
235
|
# Updating from zencoder is a two pass operation.
|
@@ -12,6 +12,8 @@ class CreateEncodableJobs < ActiveRecord::Migration
|
|
12
12
|
t.integer "zencoder_output_id"
|
13
13
|
t.string "zencoder_status"
|
14
14
|
t.string "zencoder_url"
|
15
|
+
t.string "tracking_mode"
|
16
|
+
t.integer "user_id"
|
15
17
|
t.timestamps
|
16
18
|
end
|
17
19
|
add_index :encodable_jobs, [:encodable_type, :encodable_id]
|
@@ -21,4 +23,4 @@ class CreateEncodableJobs < ActiveRecord::Migration
|
|
21
23
|
def self.down
|
22
24
|
drop_table :encodable_jobs
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end
|
@@ -58,6 +58,14 @@ module ActsAsPhocodable
|
|
58
58
|
mattr_accessor :local_base_dir
|
59
59
|
self.local_base_dir = '/tmp'
|
60
60
|
|
61
|
+
# Whether to track progress at the job level
|
62
|
+
mattr_accessor :track_jobs
|
63
|
+
self.track_jobs = true
|
64
|
+
|
65
|
+
# Whether to track progress at the component level
|
66
|
+
mattr_accessor :track_components
|
67
|
+
self.track_components = false
|
68
|
+
|
61
69
|
# The config file that tells phocoder where to find
|
62
70
|
# config options.
|
63
71
|
mattr_accessor :config_file
|
@@ -376,6 +384,12 @@ module ActsAsPhocodable
|
|
376
384
|
if self.phocodable_configuration[:local_base_dir]
|
377
385
|
ActsAsPhocodable.local_base_dir = phocodable_configuration[:local_base_dir]
|
378
386
|
end
|
387
|
+
if self.phocodable_configuration[:track_jobs]
|
388
|
+
ActsAsPhocodable.track_jobs = phocodable_configuration[:track_jobs]
|
389
|
+
end
|
390
|
+
if self.phocodable_configuration[:track_components]
|
391
|
+
ActsAsPhocodable.track_components = phocodable_configuration[:track_components]
|
392
|
+
end
|
379
393
|
|
380
394
|
|
381
395
|
if self.phocodable_configuration[:phocoder_url]
|
@@ -387,6 +401,8 @@ module ActsAsPhocodable
|
|
387
401
|
if self.phocodable_configuration[:zencoder_api_key]
|
388
402
|
::Zencoder.api_key = phocodable_configuration[:zencoder_api_key]
|
389
403
|
end
|
404
|
+
|
405
|
+
|
390
406
|
if ActsAsPhocodable.storeage_mode == "s3"
|
391
407
|
self.establish_aws_connection
|
392
408
|
end
|
@@ -485,13 +501,14 @@ module ActsAsPhocodable
|
|
485
501
|
thumb.filename = thumb_params["filename"]
|
486
502
|
thumb.width = thumb_params["width"]
|
487
503
|
thumb.height = thumb_params["height"]
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
504
|
+
if ActsAsPhocodable.track_components
|
505
|
+
tjob = thumb.encodable_jobs.new
|
506
|
+
tjob.phocoder_output_id = thumb_params["id"]
|
507
|
+
tjob.phocoder_job_id = job_id
|
508
|
+
#thumb.parent_id = self.id
|
509
|
+
tjob.phocoder_status = "phocoding"
|
510
|
+
thumb.encodable_jobs << tjob
|
511
|
+
end
|
495
512
|
thumb.encodable_status = "phocoding"
|
496
513
|
thumb.save
|
497
514
|
new_thumbs << thumb
|
@@ -536,11 +553,24 @@ module ActsAsPhocodable
|
|
536
553
|
response = Phocoder::Job.create(phocoder_params(input_thumbs))
|
537
554
|
Rails.logger.debug "the phocode response = #{response.to_json}" if Rails.env != "test"
|
538
555
|
#puts "the phocode response = #{response.to_json}" if Rails.env != "test"
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
556
|
+
if ActsAsPhocodable.track_components
|
557
|
+
job = self.encodable_jobs.new
|
558
|
+
job.phocoder_input_id = response.body["job"]["inputs"].first["id"]
|
559
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
560
|
+
job.phocoder_status = "phocoding"
|
561
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
562
|
+
self.encodable_jobs << job
|
563
|
+
end
|
564
|
+
if ActsAsPhocodable.track_jobs
|
565
|
+
job = self.encodable_jobs.new
|
566
|
+
job.tracking_mode = 'job'
|
567
|
+
job.phocoder_input_id = response.body["job"]["inputs"].first["id"]
|
568
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
569
|
+
job.phocoder_status = "phocoding"
|
570
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
571
|
+
self.encodable_jobs << job
|
572
|
+
end
|
573
|
+
|
544
574
|
self.encodable_status = "phocoding" unless self.encodable_status == "ready" # the unless clause allows new thumbs to be created on the fly without jacking with the status
|
545
575
|
self.save #false need to do save(false) here if we're calling phocode on after_save
|
546
576
|
response_thumbs = response.body["job"]["thumbnails"]
|
@@ -564,11 +594,23 @@ module ActsAsPhocodable
|
|
564
594
|
Rails.logger.debug "callback url = #{callback_url}"
|
565
595
|
response = Phocoder::Job.create(phocoder_hdr_params)
|
566
596
|
Rails.logger.debug "the response from phocode_hdr = #{response.body.to_json}"
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
597
|
+
if ActsAsPhocodable.track_components
|
598
|
+
job = self.encodable_jobs.new
|
599
|
+
job.phocoder_output_id = response.body["job"]["hdr"]["id"]
|
600
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
601
|
+
job.phocoder_status = "phocoding"
|
602
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
603
|
+
self.encodable_jobs << job
|
604
|
+
end
|
605
|
+
if ActsAsPhocodable.track_jobs
|
606
|
+
job = self.encodable_jobs.new
|
607
|
+
job.tracking_mode = 'job'
|
608
|
+
job.phocoder_output_id = response.body["job"]["hdr"]["id"]
|
609
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
610
|
+
job.phocoder_status = "phocoding"
|
611
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
612
|
+
self.encodable_jobs << job
|
613
|
+
end
|
572
614
|
self.encodable_status = "phocoding"
|
573
615
|
self.save #false need to do save(false) here if we're calling phocode on after_save
|
574
616
|
end
|
@@ -591,11 +633,23 @@ module ActsAsPhocodable
|
|
591
633
|
Rails.logger.debug "callback url = #{callback_url}"
|
592
634
|
response = Phocoder::Job.create(phocoder_hdrhtml_params)
|
593
635
|
Rails.logger.debug "the response from phocode_hdrhtml = #{response.body.to_json}"
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
636
|
+
if ActsAsPhocodable.track_components
|
637
|
+
job = self.encodable_jobs.new
|
638
|
+
job.phocoder_output_id = response.body["job"]["hdrhtml"]["id"]
|
639
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
640
|
+
job.phocoder_status = "phocoding"
|
641
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
642
|
+
self.encodable_jobs << job
|
643
|
+
end
|
644
|
+
if ActsAsPhocodable.track_jobs
|
645
|
+
job = self.encodable_jobs.new
|
646
|
+
job.tracking_mode = 'job'
|
647
|
+
job.phocoder_output_id = response.body["job"]["hdrhtml"]["id"]
|
648
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
649
|
+
job.phocoder_status = "phocoding"
|
650
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
651
|
+
self.encodable_jobs << job
|
652
|
+
end
|
599
653
|
self.encodable_status = "phocoding"
|
600
654
|
self.save #false need to do save(false) here if we're calling phocode on after_save
|
601
655
|
end
|
@@ -620,11 +674,23 @@ module ActsAsPhocodable
|
|
620
674
|
response = Phocoder::Job.create(phocoder_tone_mapping_params)
|
621
675
|
Rails.logger.debug "tone_mapping response = #{response.body.to_json}"
|
622
676
|
#puts "tone_mapping response = #{response.body.to_json}"
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
677
|
+
if ActsAsPhocodable.track_components
|
678
|
+
job = self.encodable_jobs.new
|
679
|
+
job.phocoder_output_id = response.body["job"]["tone_mapping"]["id"]
|
680
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
681
|
+
job.phocoder_status = "phocoding"
|
682
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
683
|
+
self.encodable_jobs << job
|
684
|
+
end
|
685
|
+
if ActsAsPhocodable.track_jobs
|
686
|
+
job = self.encodable_jobs.new
|
687
|
+
job.tracking_mode = 'job'
|
688
|
+
job.phocoder_output_id = response.body["job"]["tone_mapping"]["id"]
|
689
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
690
|
+
job.phocoder_status = "phocoding"
|
691
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
692
|
+
self.encodable_jobs << job
|
693
|
+
end
|
628
694
|
self.encodable_status = "phocoding"
|
629
695
|
self.save #false need to do save(false) here if we're calling phocode on after_save
|
630
696
|
response_thumbs = response.body["job"]["thumbnails"]
|
@@ -651,11 +717,23 @@ module ActsAsPhocodable
|
|
651
717
|
response = Phocoder::Job.create(phocoder_composite_params)
|
652
718
|
Rails.logger.debug "composite response = #{response.body.to_json}"
|
653
719
|
#puts "composite response = #{response.body.to_json}"
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
720
|
+
if ActsAsPhocodable.track_components
|
721
|
+
job = self.encodable_jobs.new
|
722
|
+
job.phocoder_output_id = response.body["job"]["composite"]["id"]
|
723
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
724
|
+
job.phocoder_status = "phocoding"
|
725
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
726
|
+
self.encodable_jobs << job
|
727
|
+
end
|
728
|
+
if ActsAsPhocodable.track_jobs
|
729
|
+
job = self.encodable_jobs.new
|
730
|
+
job.tracking_mode = 'job'
|
731
|
+
job.phocoder_output_id = response.body["job"]["composite"]["id"]
|
732
|
+
job.phocoder_job_id = response.body["job"]["id"]
|
733
|
+
job.phocoder_status = "phocoding"
|
734
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
735
|
+
self.encodable_jobs << job
|
736
|
+
end
|
659
737
|
self.encodable_status = "phocoding"
|
660
738
|
self.save #false need to do save(false) here if we're calling phocode on after_save
|
661
739
|
response_thumbs = response.body["job"]["thumbnails"]
|
@@ -676,21 +754,33 @@ module ActsAsPhocodable
|
|
676
754
|
Rails.logger.debug "callback url = #{callback_url}"
|
677
755
|
response = Zencoder::Job.create(zencoder_params)
|
678
756
|
Rails.logger.debug "response from Zencoder = #{response.body.to_json}"
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
757
|
+
if ActsAsPhocodable.track_components
|
758
|
+
job = self.encodable_jobs.new
|
759
|
+
job.zencoder_job_id = response.body["id"]
|
760
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
761
|
+
self.encodable_jobs << job
|
762
|
+
end
|
763
|
+
if ActsAsPhocodable.track_jobs
|
764
|
+
job = self.encodable_jobs.new
|
765
|
+
job.tracking_mode = 'job'
|
766
|
+
job.zencoder_job_id = response.body["id"]
|
767
|
+
job.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
768
|
+
self.encodable_jobs << job
|
769
|
+
end
|
770
|
+
|
683
771
|
response.body["outputs"].each do |output_params|
|
684
772
|
thumb = self.thumbnails.new()
|
685
773
|
thumb.thumbnail = output_params["label"]
|
686
774
|
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
775
|
+
if ActsAsPhocodable.track_components
|
776
|
+
tjob = thumb.encodable_jobs.new
|
777
|
+
tjob.zencoder_output_id = output_params["id"]
|
778
|
+
tjob.zencoder_url = output_params["url"]
|
779
|
+
tjob.zencoder_job_id = response.body["id"]
|
780
|
+
tjob.zencoder_status = "zencoding"
|
781
|
+
tjob.user_id = self.user_id if (self.respond_to?(:user_id) && self.user_id)
|
782
|
+
thumb.encodable_jobs << tjob
|
783
|
+
end
|
694
784
|
self.thumbnails << thumb
|
695
785
|
thumb.encodable_status = "zencoding"
|
696
786
|
thumb.save
|
@@ -57,6 +57,35 @@ describe PhocoderController do
|
|
57
57
|
#@image_upload.file_size.should == 2
|
58
58
|
end
|
59
59
|
|
60
|
+
|
61
|
+
it "should handle job tracking updates" do
|
62
|
+
@encodable_job.tracking_mode = 'job'
|
63
|
+
@encodable_job.save
|
64
|
+
post 'phocoder_notification_update', {:class=>"ImageUpload",:id=>1, :job=>{:id => 1,:type=>"ThumbnailJob"},:format=>"json", :inputs => [{}], :outputs => []}
|
65
|
+
response.should be_success
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should update all the things for job tracking updates" do
|
69
|
+
@encodable_job.tracking_mode = 'job'
|
70
|
+
@encodable_job.save
|
71
|
+
@thumbnail = @image_upload.thumbnails.create!(:thumbnail => "small")
|
72
|
+
params = {
|
73
|
+
:class=>@image_upload.class.name.to_s,:id=>@image_upload.id,
|
74
|
+
"job"=>{"state"=>"complete", "id"=>1, "type"=>"ThumbnailJob", "pixels"=>26379158, "processing_time"=>43.0},
|
75
|
+
"inputs"=>[{"id"=>50, "state"=>"complete", "file_size"=>4742478, "width"=>4288, "height"=>2848, "pixels"=>12212224, "processing_time"=>5.0, "url"=>"http://development.thephotolabs.com.s3.amazonaws.com/photos/150/dsc_8400.jpg", "lat"=>nil, "lng"=>nil, "taken_at"=>"2010-03-08T17:04:29Z", "camera_make"=>0, "camera_model"=>0, "bits_per_pixel"=>8, "exposure_time"=>"0.008000000", "f_number"=>"13.000000000", "iso_speed_rating"=>"1000", "exposure_bias_value"=>"-1.000000000", "focal_length"=>"10.000000000", "focal_length_in_35mm_film"=>"15", "subsec_time"=>74}],
|
76
|
+
"outputs"=>[{"id"=>85, "state"=>"complete", "file_size"=>69735, "label"=>"small", "url"=>"s3://development.thephotolabs.com/photo_thumbnails/150/small_dsc_8400.jpg", "pixels"=>6600, "processing_time"=>2.0, "width"=>100, "height"=>66}]
|
77
|
+
}
|
78
|
+
post 'phocoder_notification_update', params.symbolize_keys
|
79
|
+
@encodable_job.reload
|
80
|
+
@image_upload.reload
|
81
|
+
@thumbnail.reload
|
82
|
+
puts @image_upload.to_json
|
83
|
+
@encodable_job.phocoder_status.should == 'ready'
|
84
|
+
@image_upload.phocoder_status.should == 'ready'
|
85
|
+
@image_upload.width.should == 4288
|
86
|
+
@thumbnail.phocoder_status.should == 'ready'
|
87
|
+
end
|
88
|
+
|
60
89
|
end
|
61
90
|
|
62
91
|
|
@@ -120,4 +149,4 @@ describe PhocoderController do
|
|
120
149
|
|
121
150
|
|
122
151
|
|
123
|
-
end
|
152
|
+
end
|
@@ -12,6 +12,7 @@ class CreateEncodableJobs < ActiveRecord::Migration
|
|
12
12
|
t.integer "zencoder_output_id"
|
13
13
|
t.string "zencoder_status"
|
14
14
|
t.string "zencoder_url"
|
15
|
+
t.string "tracking_mode"
|
15
16
|
t.timestamps
|
16
17
|
end
|
17
18
|
add_index :encodable_jobs, [:encodable_type, :encodable_id]
|
@@ -21,4 +22,4 @@ class CreateEncodableJobs < ActiveRecord::Migration
|
|
21
22
|
def self.down
|
22
23
|
drop_table :encodable_jobs
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20121230165930) do
|
15
15
|
|
16
16
|
create_table "encodable_jobs", :force => true do |t|
|
17
17
|
t.string "encodable_type"
|
@@ -27,6 +27,7 @@ ActiveRecord::Schema.define(:version => 20120423030345) do
|
|
27
27
|
t.string "zencoder_url"
|
28
28
|
t.datetime "created_at", :null => false
|
29
29
|
t.datetime "updated_at", :null => false
|
30
|
+
t.string "tracking_mode"
|
30
31
|
end
|
31
32
|
|
32
33
|
add_index "encodable_jobs", ["encodable_type", "encodable_id"], :name => "index_encodable_jobs_on_encodable_type_and_encodable_id"
|
@@ -52,6 +52,7 @@ describe ActsAsPhocodable do
|
|
52
52
|
# )
|
53
53
|
# }
|
54
54
|
ImageUpload.destroy_all
|
55
|
+
EncodableJob.destroy_all
|
55
56
|
@fixture_path = ""
|
56
57
|
@attr = {
|
57
58
|
:file => fixture_file_upload(@fixture_path + '/big_eye_tiny.jpg','image/jpeg')
|
@@ -62,6 +63,8 @@ describe ActsAsPhocodable do
|
|
62
63
|
@txt_attr = {
|
63
64
|
:file => fixture_file_upload(@fixture_path + '/test.txt', 'text/plain')
|
64
65
|
}
|
66
|
+
ActsAsPhocodable.track_jobs = true
|
67
|
+
ActsAsPhocodable.track_components = false
|
65
68
|
end
|
66
69
|
|
67
70
|
|
@@ -97,6 +100,27 @@ describe ActsAsPhocodable do
|
|
97
100
|
ActsAsPhocodable.base_url = "http://new-domain.com"
|
98
101
|
ActsAsPhocodable.base_url.should == "http://new-domain.com"
|
99
102
|
end
|
103
|
+
|
104
|
+
it "should default to tracking jobs" do
|
105
|
+
ActsAsPhocodable.track_jobs.should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should be able to be set to not track jobs" do
|
109
|
+
ActsAsPhocodable.track_jobs = false
|
110
|
+
ActsAsPhocodable.track_jobs.should_not be_true
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should default to not tracking components" do
|
114
|
+
ActsAsPhocodable.track_components.should_not be_true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be able to be set to to track components" do
|
118
|
+
ActsAsPhocodable.track_components = true
|
119
|
+
ActsAsPhocodable.track_components.should be_true
|
120
|
+
ActsAsPhocodable.track_components = false
|
121
|
+
end
|
122
|
+
|
123
|
+
|
100
124
|
|
101
125
|
it "should default to the normal config file" do
|
102
126
|
ActsAsPhocodable.config_file.should == "config/phocodable.yml"
|
@@ -255,6 +279,34 @@ describe ActsAsPhocodable do
|
|
255
279
|
end
|
256
280
|
#
|
257
281
|
it "should call phocoder for images" do
|
282
|
+
ActsAsPhocodable.track_components = true
|
283
|
+
iu = ImageUpload.new(@attr)
|
284
|
+
|
285
|
+
Phocoder::Job.should_receive(:create).and_return(mock(Phocoder::Response,:body=>{
|
286
|
+
"job"=>{
|
287
|
+
"id"=>1,
|
288
|
+
"inputs"=>["id"=>1],
|
289
|
+
"thumbnails"=>[{"label"=>"small","filename"=>"small-test-file.jpg","id"=>1}]
|
290
|
+
}
|
291
|
+
}))
|
292
|
+
iu.save
|
293
|
+
expected_local_path = File.join('/tmp','image_uploads',iu.id.to_s,iu.filename)
|
294
|
+
File.exists?(expected_local_path).should be_true
|
295
|
+
#iu.phocode
|
296
|
+
ImageUpload.count.should == 2 #it should have created a thumbnail record
|
297
|
+
EncodableJob.count.should == 3
|
298
|
+
iu.destroy
|
299
|
+
ImageUpload.count.should == 0
|
300
|
+
EncodableJob.count.should == 3
|
301
|
+
EncodableJob.for_jobs.count.should == 1
|
302
|
+
EncodableJob.for_components.count.should == 2
|
303
|
+
File.exists?(expected_local_path).should_not be_true
|
304
|
+
ActsAsPhocodable.track_components = false
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
it "should call phocoder for images and not create encodable_jobs if we're not tracking components" do
|
309
|
+
ActsAsPhocodable.track_components = false
|
258
310
|
iu = ImageUpload.new(@attr)
|
259
311
|
|
260
312
|
Phocoder::Job.should_receive(:create).and_return(mock(Phocoder::Response,:body=>{
|
@@ -269,9 +321,12 @@ describe ActsAsPhocodable do
|
|
269
321
|
File.exists?(expected_local_path).should be_true
|
270
322
|
#iu.phocode
|
271
323
|
ImageUpload.count.should == 2 #it should have created a thumbnail record
|
324
|
+
EncodableJob.count.should == 1
|
272
325
|
iu.destroy
|
273
326
|
ImageUpload.count.should == 0
|
327
|
+
EncodableJob.count.should == 1
|
274
328
|
File.exists?(expected_local_path).should_not be_true
|
329
|
+
ActsAsPhocodable.track_components = false
|
275
330
|
end
|
276
331
|
|
277
332
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phocoder-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.49
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -254,6 +254,7 @@ files:
|
|
254
254
|
- spec/dummy/db/migrate/20110523165522_create_encodable_jobs.rb
|
255
255
|
- spec/dummy/db/migrate/20111101024507_create_images.rb
|
256
256
|
- spec/dummy/db/migrate/20120423030345_add_exif_data_to_image_uploads.rb
|
257
|
+
- spec/dummy/db/migrate/20121230165930_add_tracking_mode_to_encodable_jobs.rb
|
257
258
|
- spec/dummy/db/schema.rb
|
258
259
|
- spec/dummy/public/404.html
|
259
260
|
- spec/dummy/public/422.html
|
@@ -297,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
297
298
|
version: '0'
|
298
299
|
segments:
|
299
300
|
- 0
|
300
|
-
hash:
|
301
|
+
hash: -2014735189134116916
|
301
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
302
303
|
none: false
|
303
304
|
requirements:
|