Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delayed_Job & Whenever replaces Backgroundrb
- Loading branch information
1 parent
c9e67ca
commit 36803d5
Showing
156 changed files
with
1,457 additions
and
5,557 deletions.
There are no files selected for viewing
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
every 2.minutes do | ||
runner "FeedSource.update_feed_source" | ||
end | ||
|
||
every 3.minutes do | ||
rake "xapian:update_index" | ||
end | ||
|
||
|
27 changes: 0 additions & 27 deletions
27
db/migrate/20090119100609_create_backgroundrb_queue_table.rb
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class CreateDelayedJobs < ActiveRecord::Migration | ||
def self.up | ||
create_table :delayed_jobs, :force => true do |table| | ||
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue | ||
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually. | ||
table.text :handler # YAML-encoded string of the object that will do work | ||
table.text :last_error # reason for last failure (See Note below) | ||
table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future. | ||
table.datetime :locked_at # Set when a client is working on this object | ||
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) | ||
table.string :locked_by # Who is working on this object (if locked) | ||
table.timestamps | ||
end | ||
|
||
end | ||
|
||
def self.down | ||
drop_table :delayed_jobs | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class EncodingJob < Struct.new(:args) | ||
|
||
def perform | ||
object=args[:type].classify.constantize.find_by_id(args[:id]) | ||
success = system(convert_media(args[:type], object, args[:enc])) | ||
if success && $?.exitstatus == 0 | ||
object.update_attributes(:state=>"encoded") | ||
if args[:type]=="video" | ||
i=1 | ||
j=2 | ||
pic=4 | ||
while i<=pic do | ||
system(thumbnail(i,j,object)) | ||
i=i+1 | ||
j=j*3 | ||
end | ||
end | ||
else | ||
object.update_attributes(:state=>"encoding_error") | ||
end | ||
|
||
end | ||
|
||
# Method to convert the media to desired media (Default MP3 for Audio and FLV for Video) | ||
def convert_media(type, object, enc) | ||
media = File.join(File.dirname(object.media_type.path), "#{type}.#{enc}") | ||
File.open(media, 'w') | ||
if object.media_type.content_type.include?("audio/mpeg") || object.media_type.content_type.include?("video/x-flash-video") || object.media_type.content_type.include?("video/x-flv") | ||
command=<<-end_command | ||
cp #{ object.media_type.path } #{media} | ||
end_command | ||
command.gsub!(/\s+/, " ") | ||
elsif object.media_type.content_type.include?("video/3gpp") | ||
command = <<-end_command | ||
ffmpeg -i #{ object.media_type.path } #{object.codec_3gp} #{ media } | ||
end_command | ||
command.gsub!(/\s+/, " ") | ||
else | ||
command = <<-end_command | ||
ffmpeg -i #{ object.media_type.path } #{object.codec} #{ media } | ||
end_command | ||
command.gsub!(/\s+/, " ") | ||
end | ||
end | ||
|
||
# Create Thumbnails for Video File on Particular Intervals | ||
def thumbnail(i,j,object) | ||
thumb = File.join(File.dirname(object.media_type.path), "#{i.to_s}.png") | ||
File.open(thumb, 'w') | ||
command=<<-end_command | ||
ffmpeg -itsoffset -#{(i*j).to_s} -i #{File.dirname(object.media_type.path)}/video.flv -vcodec png -vframes 1 -an -f rawvideo -s 470x320 -y #{thumb} | ||
end_command | ||
command.gsub!(/\s+/, " ") | ||
end | ||
end | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class NewsletterJob | ||
|
||
def perform | ||
command=<<-end_command | ||
ruby script/runner QueuedMail.send_email | ||
end_command | ||
command.gsub!(/\s+/, " ") | ||
if system(command) | ||
p "#{Time.now} : Newsletter sending success#{ $?.exitstatus == 0 ? '' : ', but exit status equal to '+exitstatus.to_s }" | ||
else | ||
p "#{Time.now} : Newsletter sending failed" | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.