I need something sending emails on demand.
Each user in my app should be able to set a date and hour when he will receive an email periodically, reminding that she or him has to take medicines.
Is it possible to handle this with a custom daemon? I think so, but its my first time with this stuff and I need your opinion to be sure before starting.
http://railscasts.com/episodes/129-custom-daemon
Thanks a lot, guys.
Edit:
medicine_worker.rb:
class MedicineWorker
include Sidekiq::Worker
sidekiq_options retry: false
def perform(name, count)
puts 'Doing hard work'
end
end
redis.rb:
# bundle exec sidekiq
$redis = Redis.new(:host => 'localhost', :port => 6379)
bundle exec sidekiq:
2014-08-26T14:57:17.321Z 1754 TID-znnu9k INFO: Running in ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
2014-08-26T14:57:17.321Z 1754 TID-znnu9k INFO: See LICENSE and the LGPL-3.0 for licensing details.
2014-08-26T14:57:17.321Z 1754 TID-znnu9k INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org/pro
2014-08-26T14:57:17.321Z 1754 TID-znnu9k INFO: Starting processing, hit Ctrl-C to stop
2014-08-26T14:57:17.374Z 1754 TID-zvhqi8 MedicineWorker JID-d3b450f5fd4b926ea70f1c13 INFO: start
Doing hard work
2014-08-26T14:57:17.374Z 1754 TID-zvgu8k MedicineWorker JID-f4958c2fb72aabd91d53b02b INFO: start
Doing hard work
2014-08-26T14:57:17.375Z 1754 TID-zvgbmk MedicineWorker JID-104ee301c6e5a034f42ed06d INFO: start
Doing hard work2014-08-26T14:57:17.375Z 1754 TID-zvfigk MedicineWorker JID-5698a08a24a3def961908dc1 INFO: start
Doing hard work2014-08-26T14:57:17.376Z 1754 TID-zt4ps4 MedicineWorker JID-36d06312e1fdfe8cc439ddbd INFO: start
Doing hard work
2014-08-26T14:57:17.377Z 1754 TID-zvgu8k MedicineWorker JID-f4958c2fb72aabd91d53b02b INFO: done: 0.003 sec
2014-08-26T14:57:17.378Z 1754 TID-zt3qkc MedicineWorker JID-b25e0e7be05580e358c6744a INFO: start
Doing hard work
2014-08-26T14:57:17.379Z 1754 TID-zvhqi8 MedicineWorker JID-d3b450f5fd4b926ea70f1c13 INFO: done: 0.005 sec
2014-08-26T14:57:17.380Z 1754 TID-zvgbmk MedicineWorker JID-104ee301c6e5a034f42ed06d INFO: done: 0.005 sec
2014-08-26T14:57:17.380Z 1754 TID-zvgqac MedicineWorker JID-38a185bc67c673062c475faf INFO: start
Doing hard work2014-08-26T14:57:17.380Z 1754 TID-zvhbbk MedicineWorker JID-d2058fcebd88210c406b49e4 INFO: start
Doing hard work2014-08-26T14:57:17.383Z 1754 TID-zt4ps4 MedicineWorker JID-36d06312e1fdfe8cc439ddbd INFO: done: 0.007 sec
2014-08-26T14:57:17.384Z 1754 TID-zvfigk MedicineWorker JID-5698a08a24a3def961908dc1 INFO: done: 0.009 sec
2014-08-26T14:57:17.385Z 1754 TID-zvf9k0 MedicineWorker JID-cc5e3ee8ddeead76d0c1fc5b INFO: start
Doing hard work2014-08-26T14:57:17.385Z 1754 TID-zvg6c0 MedicineWorker JID-d83dc9cb10b69c1680305417 INFO: start
Doing hard work
2014-08-26T14:57:17.385Z 1754 TID-zt4h14 MedicineWorker JID-9d13fbed1bb0042eea452ec5 INFO: start
Doing hard work
2014-08-26T14:57:17.388Z 1754 TID-zt5uv0 MedicineWorker JID-877e16ded3e18828e3396719 INFO: start
Doing hard work2014-08-26T14:57:17.389Z 1754 TID-zt3qkc MedicineWorker JID-b25e0e7be05580e358c6744a INFO: done: 0.011 sec
2014-08-26T14:57:17.389Z 1754 TID-10h4kzs MedicineWorker JID-6739ea8a340b44c06da9dabf INFO: start
Doing hard work
2014-08-26T14:57:17.390Z 1754 TID-10h4pi0 MedicineWorker JID-dcb9282efabb6c9948014834 INFO: start
Doing hard work
2014-08-26T14:57:17.391Z 1754 TID-zt1wnk MedicineWorker JID-c6fa12391faff774ffda3f5b INFO: start
Doing hard work
2014-08-26T14:57:17.392Z 1754 TID-10h6pco MedicineWorker JID-44d7747775163b4f8bf40af8 INFO: start
Doing hard work
2014-08-26T14:57:17.393Z 1754 TID-10h6u2o MedicineWorker JID-212baee3c6f3526a3ff24d9c INFO: start
Doing hard work
2014-08-26T14:57:17.394Z 1754 TID-10h5cvo MedicineWorker JID-27f2009864a0e63ab4cab2d3 INFO: start
Doing hard work2014-08-26T14:57:17.446Z 1754 T
.......
.......
.......
You better use a Background Queue for this preferably one with a scheduling option.
Sidekiq is pretty good for what you need.
https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs
Related
As you can see in the stack trace below, Reminders::FindStaleJobsJob is causing a problem because of the uninitialized constant Reminders. What I don't get is that I don't call Reminders::FindStaleJobsJob anywhere; rather, I call Recaps::FindStaleJobsJob.
I have flushed out the Sidekiq queue and still get this error repeatedly.
2018-09-25T17:45:14.539Z 12784 TID-oxxicof3s INFO: Running in ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
2018-09-25T17:45:14.539Z 12784 TID-oxxicof3s INFO: See LICENSE and the LGPL-3.0 for licensing details.
2018-09-25T17:45:14.539Z 12784 TID-oxxicof3s INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2018-09-25T17:45:14.541Z 12784 TID-oxxicof3s INFO: Starting processing, hit Ctrl-C to stop
2018-09-25T18:00:05.107Z 12784 TID-oxxi975os Recaps::FindStaleJobsJob JID-ec113586e3f8fe72eb3ca479 INFO: start
2018-09-25T18:00:05.135Z 12784 TID-oxxim1crg ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-4bc5f87567ca3f019b2015e4 INFO: start
2018-09-25T18:00:05.136Z 12784 TID-oxxi970ss Recaps::FindStaleJobsJob JID-3125783fd5da7604b95bb813 INFO: start
2018-09-25T18:00:05.155Z 12784 TID-oxxim1crg ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-4bc5f87567ca3f019b2015e4 INFO: fail: 0.02 sec
2018-09-25T18:00:05.155Z 12784 TID-oxxim1crg WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","queue":"default","description":"","args":[{"job_class":"Reminders::FindStaleJobsJob","job_id":"d6161fcf-2abd-4e2b-8946-73668a78282f","queue_name":"default","arguments":[]}],"retry":true,"jid":"4bc5f87567ca3f019b2015e4","created_at":1537898405.1336598,"enqueued_at":1537898405.133705},"jobstr":"{\"class\":\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"queue\":\"default\",\"description\":\"\",\"args\":[{\"job_class\":\"Reminders::FindStaleJobsJob\",\"job_id\":\"d6161fcf-2abd-4e2b-8946-73668a78282f\",\"queue_name\":\"default\",\"arguments\":[]}],\"retry\":true,\"jid\":\"4bc5f87567ca3f019b2015e4\",\"created_at\":1537898405.1336598,\"enqueued_at\":1537898405.133705}"}
2018-09-25T18:00:05.155Z 12784 TID-oxxim1crg WARN: NameError: uninitialized constant Reminders
My Sidekiq cron initializer:
#/config/initializers/sidekiq_cron_scheduler.rb
jobs_hash = {
'recap' => {
'class' => 'Recaps::FindStaleJobsJob',
'cron' => '0, 15, 30, 45 * * * *',
'active_job' => true
}
}
Sidekiq::Cron::Job.load_from_hash jobs_hash
Am I doing something silly and obvious?
Something was hung up somewhere. I removed the Recaps module from the sidekiq-cron initializer and let it fail on that. Then I reintroduced the module name and with a few redis-cli flushall commands sprinkled and there, and everything seems to be working fine.
Is there an easy method to see the elapsed time of a sidekiq job?
The log output?
ScheduledWorker JID-072f6c37f240a92ca3c07914 INFO: start
ScheduledWorker JID-072f6c37f240a92ca3c07914 INFO: done: 0.003 sec
I am new to rails. I am doing exactly (copy paste) per
https://www.pubnub.com/blog/2015-12-08-building-video-sharing-app-server-messaging-ruby/
On top of this I am running
redis -server
and
bundle exec sidekiq
but I get message "Video is still being encoded."
I checked in database and my videos are getting inserted. Here's the log for Redis and sidekiq
Redis--
$ redis-server
[64544] 11 Oct 07:36:14.426 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[64544] 11 Oct 07:36:14.427 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 8160.
[64544] 11 Oct 07:36:14.427 # Creating Server TCP listening socket *:6379: bind: Address already in use
below is sidekiq log
2016-10-12T04:21:00.251Z 73605 TID-l83gw INFO: [Sidetiq] Enqueue: VideoPublisher (at: 1476246120.0) (last: 1476246060.0)
2016-10-12T04:21:16.178Z 73605 TID-oxkz28srs VideoPublisher JID-19a982e30a3c181f8f757b50 INFO: start
2016-10-12T04:21:16.180Z 73605 TID-oxkz28srs VideoPublisher JID-19a982e30a3c181f8f757b50 INFO: done: 0.002 sec
2016-10-12T04:22:00.271Z 73605 TID-ou3i0 INFO: [Sidetiq] Enqueue: VideoPublisher (at: 1476246180.0) (last: 1476246120.0)
2016-10-12T04:22:16.146Z 73605 TID-v65wg VideoPublisher JID-e0c8138c9c3bdbcef3711c76 INFO: start
2016-10-12T04:22:16.149Z 73605 TID-v65wg VideoPublisher JID-e0c8138c9c3bdbcef3711c76 INFO: done: 0.003 sec
2016-10-12T04:22:31.984Z 73605 TID-y7u04 ThumbnailCutter JID-da2c68736611327a846e7df6 INFO: start
sidekiq 4.2.2 VideoShrimp [0 of 25 busy]: No such file or directory - ffmpeg
2016-10-12T04:22:31.991Z 73605 TID-y7u04 ThumbnailCutter JID-da2c68736611327a846e7df6 INFO: fail: 0.007 sec
2016-10-12T04:22:31.991Z 73605 TID-y7u04 WARN: {"class":"ThumbnailCutter","args":[7],"retry":true,"queue":"default","jid":"da2c68736611327a846e7df6","created_at":1476245384.080985,"enqueued_at":1476246151.9836948,"error_message":"exception class/object expected","error_class":"TypeError","failed_at":1476245384.2300832,"retry_count":5,"retried_at":1476246151.9909208}
2016-10-12T04:22:31.991Z 73605 TID-y7u04 WARN: TypeError: exception class/object expected
2016-10-12T04:22:31.991Z 73605 TID-y7u04 WARN: /home/ubuntu/ruby_projects/VideoShrimp/app/workers/thumbnail_cutter.rb:13:in raise' /home/ubuntu/ruby_projects/VideoShrimp/app/workers/thumbnail_cutter.rb:13:inperform'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:155:in execute_job' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:136:inblock (3 levels) in process'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:128:in block in invoke' /usr/local/rvm/gems/ruby-2.2.1/bundler/gems/sidetiq-7bec4084165f/lib/sidetiq/middleware/history.rb:8:incall'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:130:in block in invoke' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/server/active_record.rb:6:incall'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:130:in block in invoke' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/server/retry_jobs.rb:74:incall'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:130:in block in invoke' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/server/logging.rb:11:inblock in call'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/logging.rb:32:in with_context' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/server/logging.rb:7:incall'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:130:in block in invoke' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:133:incall'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/middleware/chain.rb:133:in invoke' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:131:inblock (2 levels) in process'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:171:in stats' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:130:inblock in process'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq.rb:35:in call' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq.rb:35:inblock in module:Sidekiq'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:122:in call' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:122:inprocess'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:81:in process_one' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/processor.rb:69:inrun'
/usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/util.rb:17:in watchdog' /usr/local/rvm/gems/ruby-2.2.1/gems/sidekiq-4.2.2/lib/sidekiq/util.rb:25:inblock in safe_thread'
2016-10-12T04:23:00.332Z 73605 TID-l83gw INFO: [Sidetiq] Enqueue: VideoPublisher (at: 1476246240.0) (last: 1476246180.0)
2016-10-12T04:23:03.189Z 73605 TID-nzbss VideoPublisher JID-3868cff6ecf16611b931cab4 INFO: start
2016-10-12T04:23:03.202Z 73605 TID-nzbss VideoPublisher JID-3868cff6ecf16611b931cab4 INFO: done: 0.013 sec
2016-10-12T04:24:00.354Z 73605 TID-ou3i0 INFO: [Sidetiq] Enqueue: VideoPublisher (at: 1476246300.0) (last: 1476246240.0)
2016-10-12T04:24:01.846Z 73605 TID-vgq5w VideoPublisher JID-267f4344c307579fa8ba2a52 INFO: start
2016-10-12T04:24:01.848Z 73605 TID-vgq5w VideoPublisher JID-267f4344c307579fa8ba2a52 INFO: done: 0.002 sec
sidekiq 4.2.2 VideoShrimp [0 of 25 busy]: No such file or directory - ffmpeg - You don't have ffmpeg installed on your system or executable is not in your PATH.
Installing ffmpeg should help, you can do that on ubuntu this way: sudo apt-get install ffmpeg (I'm assuming you're on ubuntu because of /home/ubuntu).
The [64544] 11 Oct 07:36:14.427 # Creating Server TCP listening socket *:6379: bind: Address already in use indicates that socket is already in use so you probably have redis server already running.
I'm using the latest version of Sidekiq (2.15.2). I'm not sure how this happened but for some reason, my Sidekiq dashboard always has 2 busy processes.
When I click on busy, I just get the message, "Internal Server Error."
I tried stopping and restarting Sidekiq, but I still get the 2 busy processes. Does anyone have any suggestions? Thanks!
Here is my log after resetting Sidekiq.
2013-11-13T05:09:02Z 2508 TID-osg9yldog INFO: Received USR1, no longer accepting new work
2013-11-13T05:09:02Z 2508 TID-osgbbuwe4 INFO: Shutting down 25 quiet workers
2013-11-13T05:09:04Z 2593 TID-ow9gk2yd0 INFO: Received USR1, no longer accepting new work
2013-11-13T05:09:04Z 2593 TID-ow9hyfa04 INFO: Shutting down 25 quiet workers
2013-11-13T05:09:32Z 2508 TID-osg9yldog INFO: Shutting down
2013-11-13T05:09:32Z 2508 TID-osgbbuwe4 INFO: Shutting down 0 quiet workers
2013-11-13T05:09:36Z 2593 TID-ow9gk2yd0 INFO: Shutting down
2013-11-13T05:09:36Z 2593 TID-ow9hyfa04 INFO: Shutting down 0 quiet workers
2013-11-13T05:10:33Z 15613 TID-osg19rhj4 INFO: Booting Sidekiq 2.15.2 using redis://localhost:6379/0 with options {}
2013-11-13T05:10:33Z 15613 TID-osg19rhj4 INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
2013-11-13T05:10:33Z 15613 TID-osg19rhj4 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-11-13T05:10:33Z 15613 TID-osg19rhj4 INFO: Starting processing, hit Ctrl-C to stop
2013-11-13T05:10:33Z 15698 TID-ox8r4hzlg INFO: Booting Sidekiq 2.15.2 using redis://localhost:6379/0 with options {}
2013-11-13T05:10:33Z 15698 TID-ox8r4hzlg INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
2013-11-13T05:10:33Z 15698 TID-ox8r4hzlg INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-11-13T05:10:33Z 15698 TID-ox8r4hzlg INFO: Starting processing, hit Ctrl-C to stop
If you are using a default redis.conf you'll find the following lines:
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir ./
This means Redis will write on those periods a snapshot of the current status.
When you are developing probably you'd like to delete this file or commenting all the save lines as per redis.conf document before restarting the server again, or it will try to pick up any previous activity.
When I create a new user on GitLab the email is not sent to the new user's email inbox.
I am new to GitLab so don't know in-depth of it. here goes the log of "sidekiq.log"
2013-11-06T04:03:55Z 2747 TID--9ygdxi INFO: Booting Sidekiq 2.14.0 using redis://localhost:6379 with options {:namespace=>"resque:gitlab"}
2013-11-06T04:03:55Z 2747 TID--9ygdxi INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
2013-11-06T04:03:55Z 2747 TID--9ygdxi INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-11-06T04:13:08Z 2747 TID--9rl0h4 Sidekiq::Extensions::DelayedMailer JID-6ba7a5bad5ed737cf49d9ad9 INFO: start
2013-11-06T04:13:08Z 2747 TID--9rl0h4 Sidekiq::Extensions::DelayedMailer JID-6ba7a5bad5ed737cf49d9ad9 INFO: done: 0.339 sec
2013-11-06T05:09:09Z 2747 TID--9rl0h4 Sidekiq::Extensions::DelayedMailer JID-312cc90acce9945981cc9cc0 INFO: start
2013-11-06T05:09:09Z 2747 TID--9rl0h4 Sidekiq::Extensions::DelayedMailer JID-312cc90acce9945981cc9cc0 INFO: done: 0.114 sec
Let me know how to come over this issue? do I need to run any other services?
I did it by myself, I found what was wrong. I reinstalled postfix and selected internet site its working fine now. In previous install I selected some local option.