Class: QueueJob
- Inherits:
-
Struct
- Object
- Struct
- QueueJob
- Defined in:
- app/jobs/queue_job.rb
Defined Under Namespace
Classes: Message
Instance Attribute Summary collapse
-
#event_id ⇒ Object
Returns the value of attribute event_id.
Instance Method Summary collapse
- #do_email(sub, message, msg) ⇒ Object
- #do_ios(sub, message, msg, ios) ⇒ Object
- #do_twitter(sub, message, twitter, msg) ⇒ Object
- #do_web(sub, sent, msg) ⇒ Object
- #error(job, e) ⇒ Object
- #perform ⇒ Object
- #success(job) ⇒ Object
Instance Attribute Details
#event_id ⇒ Object
Returns the value of attribute event_id
3 4 5 |
# File 'app/jobs/queue_job.rb', line 3 def event_id @event_id end |
Instance Method Details
#do_email(sub, message, msg) ⇒ Object
96 97 98 99 100 |
# File 'app/jobs/queue_job.rb', line 96 def do_email(sub, , msg) .destination = sub.q_user.email QueueMailer.delay.notification(.id, sub.q_user.email, sub.q_publisher.mail_from, msg.h1, msg.body) .status = "PENDING" end |
#do_ios(sub, message, msg, ios) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/jobs/queue_job.rb', line 102 def do_ios(sub, , msg, ios) notification = Grocer::Notification.new( device_token: sub.q_user.ios_device_token, alert: msg.body, sound: "siren.aiff", expiry: Time.now + 60*60, ) ios.push(notification) .destination = "iOS" .status = "OK" end |
#do_twitter(sub, message, twitter, msg) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/jobs/queue_job.rb', line 78 def do_twitter(sub, , twitter, msg) unless twitter .status = 'Twitter not configured' return end if sub.q_user.source==1 twitter.update(msg.body) # tweet .destination = "tweet" else return unless sub.q_user.twitter_handle.not_blank? twitter.(sub.q_user.twitter_handle, msg.body) # direct message .destination = "@#{sub.q_user.twitter_handle}" end .status = "OK" end |
#do_web(sub, sent, msg) ⇒ Object
115 116 117 118 |
# File 'app/jobs/queue_job.rb', line 115 def do_web(sub, sent, msg) .status = "PENDING" # do nothing - let the web api offer up the messages end |
#error(job, e) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'app/jobs/queue_job.rb', line 120 def error(job, e) notes = [] notes << "Exception Message: #{e.}" notes << "Stack Trace: #{e.backtrace.join("\n")}" reference = Digest::MD5.hexdigest(Time.now.to_s)[0..8] Event.store("QueueJob error", nil, 0, notes.join("\n"), reference) Rails.logger.error "QueueJob error: #{reference} #{e.}" end |
#perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/jobs/queue_job.rb', line 9 def perform @event = QEvent.find(event_id) return if @event.processed_at = {} # keyed on klass, i.e. the database record which shows how to generate the message body twitter = Twitter::publisher.new( :consumer_key => @event.q_publisher.twitter_consumer_key, :consumer_secret => @event.q_publisher.twitter_consumer_secret, :oauth_token => @event.q_publisher.twitter_oauth_token, :oauth_token_secret => @event.q_publisher.twitter_oauth_token_secret ) rescue nil ios = Grocer.pusher( certificate: StringIO.new(@event.q_publisher.ios_certificate), port: 2195, retries: 3 ) rescue nil QSubscription.sys(@event.system_id).where(:q_publisher_id=>@event.q_publisher_id).where(:topic=>@event.topic).includes(:q_user).find_each do |sub| sub.q_user.q_users_methods.each do |method| msg = [method] unless msg klass = QKlass.sys(@event.system_id).where(:q_publisher_id=>@event.q_publisher_id).where(:name=>@event.klass).first if klass body = eval(klass.) h1 = eval(klass.h1_code) h2 = eval(klass.h2_code) else body = @event.data h1 = "" h2 = "" end msg = Message.new msg.body = body msg.h1 = h1 msg.h2 = h2 [method] = msg end = QMessage.new(:q_publisher=>@event.q_publisher, :q_event=>@event, :q_subscription=>sub, :q_user=>sub.q_user, :body=>msg.body, :h1=>msg.h1, :h2=>msg.h2, :system_id=>@event.system_id) next unless msg.body.not_blank? begin if method=='twitter' do_twitter(sub, , msg, twitter) elsif method=='email' do_email(sub, , msg) elsif method=='ios' do_ios(sub, , msg, ios) elsif method=='web' do_web(sub, , msg) end rescue Exception => e .status = e. end .save end sub.last_notification = Time.now sub.save end @event.processed_at = Time.now @event.save end |
#success(job) ⇒ Object
129 130 |
# File 'app/jobs/queue_job.rb', line 129 def success(job) end |