rufus-scheduler 3.7.0 → 3.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0572c41e8ad285c2de6828cc86ef489122cea65c412514566c08c35713a0523
4
- data.tar.gz: 327a0c5e462acc3df68d6c55366a956c9e16b4b4adf208b103568cce4f943dd6
3
+ metadata.gz: 9fbe0f73068129b96196031b141f480f830e3110e35d3c5eaa2206530b1ae536
4
+ data.tar.gz: bec310a43820928b8d342b5b3602edf8cb27aaca8995e0a18073d70dfd3839f8
5
5
  SHA512:
6
- metadata.gz: e3153aa15933ee24cf3a11657fb0b8bd3d58d87e054b20d9d759b52cdd924a418fcf95ef1e14b980b459a501ccce91b285cd85c826e0fa4207fac85f69c77667
7
- data.tar.gz: e7af296c9864ffc392ef44eec1bb6ed0331065658b9d9d1225cd2c1f62d1d67302db7075540b0c39a99dcf5f741471f3c38666cb8870165cca23a34f52f1c7df
6
+ metadata.gz: 3e8edfd4df2ddbb0f8026ffa13fff69f9f4bd045da1638fe5ac38610992e0f7d173b20a27ad1833760d6fee62d41b5b160978e107dbc55a1b9d07dfaa62444ad
7
+ data.tar.gz: 412bb7e80546c5cd13bf8875f928ce6920a9e62774d296db83935adbfee56069cbb2729bb4640962351297cd55b8b5cfb92facfec38e7cb92b3ef9f7446c7283
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ### rufus-scheduler 3.8.2 - released 2022-07-12
6
+
7
+ * Prevent error in shutdown when @thread is current Thread, gh-337
8
+ * Rescue errors on the scheduling thread, gh-335
9
+
10
+
11
+ ### rufus-scheduler 3.8.1 - released 2022-01-11
12
+
13
+ * Suppress warning about @resume_discard_past
14
+ * Suppress warning about unused variable, solackerman gh-332
15
+
16
+
17
+ ### rufus-scheduler 3.8.0 - released 2021-07-14
18
+
19
+ * Add #source_location to Job, gh-322
20
+
21
+
5
22
  ### rufus-scheduler 3.7.0 - released 2020-12-31
6
23
 
7
24
  * Implement Job name:/n: #name and #name=, gh-309
data/CREDITS.md CHANGED
@@ -4,7 +4,12 @@
4
4
 
5
5
  ## Contributors
6
6
 
7
- * John Bachir https://github.com/jjb gh-310
7
+ * Bence Monus https://github.com/cromega gh-337 on_error and friends
8
+ * Talia Wong https://github.com/blowfishpro gh-335 on_error and friends
9
+ * Konstantin https://github.com/fa11enangel gh-334 nodejitsu link
10
+ * Olle Jonsson https://github.com/olleolleolle gh-333
11
+ * Sol Ackerman https://github.com/solarckerman gh-332
12
+ * John Bachir https://github.com/jjb gh-310 gh-327
8
13
  * Daniel Berger https://github.com/djberg96 gh-300
9
14
  * Ceyhun Onur https://github.com/ceyonur parse_cron no_error: true
10
15
  * Darwin Wu https://github.com/dwaxe Rails initializer vs tests change
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2005-2020, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2005-2022, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # rufus-scheduler
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/jmettraux/rufus-scheduler.svg)](https://travis-ci.org/jmettraux/rufus-scheduler)
4
+ [![tests](https://github.com/jmettraux/rufus-scheduler/workflows/test/badge.svg)](https://github.com/jmettraux/rufus-scheduler/actions)
5
5
  [![Gem Version](https://badge.fury.io/rb/rufus-scheduler.svg)](https://badge.fury.io/rb/rufus-scheduler)
6
6
  [![Join the chat at https://gitter.im/floraison/fugit](https://badges.gitter.im/floraison/fugit.svg)](https://gitter.im/floraison/fugit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
7
 
@@ -133,7 +133,7 @@ Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmett
133
133
  ### faq
134
134
 
135
135
  * [It doesn't work...](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html)
136
- * [I want a refund](https://blog.nodejitsu.com/getting-refunds-on-open-source-projects)
136
+ * [I want a refund](https://web.archive.org/web/20160425034214/http://blog.nodejitsu.com/getting-refunds-on-open-source-projects/)
137
137
  * [Passenger and rufus-scheduler](https://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180)
138
138
  * [Passenger and rufus-scheduler (2)](https://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555)
139
139
  * [Passenger in-depth spawn methods](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/)
@@ -223,7 +223,7 @@ job =
223
223
  # also
224
224
 
225
225
  job =
226
- scheduler.in '10d', :job => true do
226
+ scheduler.in '10d', job: true do
227
227
  # ...
228
228
  end
229
229
  ```
@@ -378,7 +378,7 @@ While paused, the scheduler still accepts schedules, but no schedule will get tr
378
378
 
379
379
  ## job options
380
380
 
381
- ### :name => string
381
+ ### name: string
382
382
 
383
383
  Sets the name of the job.
384
384
 
@@ -395,23 +395,23 @@ job1 =
395
395
  job1.name = 'Beowulf'
396
396
  ```
397
397
 
398
- ### :blocking => true
398
+ ### blocking: true
399
399
 
400
- By default, jobs are triggered in their own, new threads. When `:blocking => true`, the job is triggered in the scheduler thread (a new thread is not created). Yes, while a blocking job is running, the scheduler is not scheduling.
400
+ By default, jobs are triggered in their own, new threads. When `blocking: true`, the job is triggered in the scheduler thread (a new thread is not created). Yes, while a blocking job is running, the scheduler is not scheduling.
401
401
 
402
- ### :overlap => false
402
+ ### overlap: false
403
403
 
404
404
  Since, by default, jobs are triggered in their own new threads, job instances might overlap. For example, a job that takes 10 minutes and is scheduled every 7 minutes will have overlaps.
405
405
 
406
- To prevent overlap, one can set `:overlap => false`. Such a job will not trigger if one of its instances is already running.
406
+ To prevent overlap, one can set `overlap: false`. Such a job will not trigger if one of its instances is already running.
407
407
 
408
408
  The `:overlap` option is considered before the `:mutex` option when the scheduler is reviewing jobs for triggering.
409
409
 
410
- ### :mutex => mutex_instance / mutex_name / array of mutexes
410
+ ### mutex: mutex_instance / mutex_name / array of mutexes
411
411
 
412
412
  When a job with a mutex triggers, the job's block is executed with the mutex around it, preventing other jobs with the same mutex from entering (it makes the other jobs wait until it exits the mutex).
413
413
 
414
- This is different from `:overlap => false`, which is, first, limited to instances of the same job, and, second, doesn't make the incoming job instance block/wait but give up.
414
+ This is different from `overlap: false`, which is, first, limited to instances of the same job, and, second, doesn't make the incoming job instance block/wait but give up.
415
415
 
416
416
  `:mutex` accepts a mutex instance or a mutex name (String). It also accept an array of mutex names / mutex instances. It allows for complex relations between jobs.
417
417
 
@@ -421,12 +421,12 @@ Note: creating lots of different mutexes is OK. Rufus-scheduler will place them
421
421
 
422
422
  The `:overlap` option is considered before the `:mutex` option when the scheduler is reviewing jobs for triggering.
423
423
 
424
- ### :timeout => duration or point in time
424
+ ### timeout: duration or point in time
425
425
 
426
426
  It's OK to specify a timeout when scheduling some work. After the time specified, it gets interrupted via a Rufus::Scheduler::TimeoutError.
427
427
 
428
428
  ```ruby
429
- scheduler.in '10d', :timeout => '1d' do
429
+ scheduler.in '10d', timeout: '1d' do
430
430
  begin
431
431
  # ... do something
432
432
  rescue Rufus::Scheduler::TimeoutError
@@ -447,15 +447,15 @@ In the case of an "every" job, this will be the first time (modulo the scheduler
447
447
  For a "cron" job as well, the :first will point to the first time the job has to trigger, the following trigger times are then determined by the cron string.
448
448
 
449
449
  ```ruby
450
- scheduler.every '2d', :first_at => Time.now + 10 * 3600 do
450
+ scheduler.every '2d', first_at: Time.now + 10 * 3600 do
451
451
  # ... every two days, but start in 10 hours
452
452
  end
453
453
 
454
- scheduler.every '2d', :first_in => '10h' do
454
+ scheduler.every '2d', first_in: '10h' do
455
455
  # ... every two days, but start in 10 hours
456
456
  end
457
457
 
458
- scheduler.cron '00 14 * * *', :first_in => '3d' do
458
+ scheduler.cron '00 14 * * *', first_in: '3d' do
459
459
  # ... every day at 14h00, but start after 3 * 24 hours
460
460
  end
461
461
  ```
@@ -477,7 +477,7 @@ s = Rufus::Scheduler.new
477
477
 
478
478
  n = Time.now; p [ :scheduled_at, n, n.to_f ]
479
479
 
480
- s.every '3s', :first => :now do
480
+ s.every '3s', first: :now do
481
481
  n = Time.now; p [ :in, n, n.to_f ]
482
482
  end
483
483
 
@@ -502,15 +502,15 @@ This option is for repeat jobs (cron / every) only.
502
502
  It indicates the point in time after which the job should unschedule itself.
503
503
 
504
504
  ```ruby
505
- scheduler.cron '5 23 * * *', :last_in => '10d' do
505
+ scheduler.cron '5 23 * * *', last_in: '10d' do
506
506
  # ... do something every evening at 23:05 for 10 days
507
507
  end
508
508
 
509
- scheduler.every '10m', :last_at => Time.now + 10 * 3600 do
509
+ scheduler.every '10m', last_at: Time.now + 10 * 3600 do
510
510
  # ... do something every 10 minutes for 10 hours
511
511
  end
512
512
 
513
- scheduler.every '10m', :last_in => 10 * 3600 do
513
+ scheduler.every '10m', last_in: 10 * 3600 do
514
514
  # ... do something every 10 minutes for 10 hours
515
515
  end
516
516
  ```
@@ -525,16 +525,16 @@ job.last_at = Rufus::Scheduler.parse('2029-12-12')
525
525
  # set the last bound
526
526
  ```
527
527
 
528
- ### :times => nb of times (before auto-unscheduling)
528
+ ### times: nb of times (before auto-unscheduling)
529
529
 
530
530
  One can tell how many times a repeat job (CronJob or EveryJob) is to execute before unscheduling by itself.
531
531
 
532
532
  ```ruby
533
- scheduler.every '2d', :times => 10 do
533
+ scheduler.every '2d', times: 10 do
534
534
  # ... do something every two days, but not more than 10 times
535
535
  end
536
536
 
537
- scheduler.cron '0 23 * * *', :times => 31 do
537
+ scheduler.cron '0 23 * * *', times: 31 do
538
538
  # ... do something every day at 23:00 but do it no more than 31 times
539
539
  end
540
540
  ```
@@ -542,7 +542,7 @@ end
542
542
  It's OK to assign nil to :times to make sure the repeat job is not limited. It's useful when the :times is determined at scheduling time.
543
543
 
544
544
  ```ruby
545
- scheduler.cron '0 23 * * *', :times => nolimit ? nil : 10 do
545
+ scheduler.cron '0 23 * * *', times: (nolimit ? nil : 10) do
546
546
  # ...
547
547
  end
548
548
  ```
@@ -564,7 +564,7 @@ job.times = 10
564
564
 
565
565
  ## Job methods
566
566
 
567
- When calling a schedule method, the id (String) of the job is returned. Longer schedule methods return Job instances directly. Calling the shorter schedule methods with the :job => true also returns Job instances instead of Job ids (Strings).
567
+ When calling a schedule method, the id (String) of the job is returned. Longer schedule methods return Job instances directly. Calling the shorter schedule methods with the `job: true` also returns Job instances instead of Job ids (Strings).
568
568
 
569
569
  ```ruby
570
570
  require 'rufus-scheduler'
@@ -582,7 +582,7 @@ When calling a schedule method, the id (String) of the job is returned. Longer s
582
582
  end
583
583
 
584
584
  job =
585
- scheduler.in '1w', :job => true do
585
+ scheduler.in '1w', job: true do
586
586
  # ...
587
587
  end
588
588
  ```
@@ -608,7 +608,7 @@ Returns the scheduler instance itself.
608
608
  Returns the options passed at the Job creation.
609
609
 
610
610
  ```ruby
611
- job = scheduler.schedule_in('10d', :tag => 'hello') do; end
611
+ job = scheduler.schedule_in('10d', tag: 'hello') do; end
612
612
  job.opts
613
613
  # => { :tag => 'hello' }
614
614
  ```
@@ -618,7 +618,7 @@ job.opts
618
618
  Returns the original schedule.
619
619
 
620
620
  ```ruby
621
- job = scheduler.schedule_in('10d', :tag => 'hello') do; end
621
+ job = scheduler.schedule_in('10d', tag: 'hello') do; end
622
622
  job.original
623
623
  # => '10d'
624
624
  ```
@@ -665,12 +665,30 @@ job.callable
665
665
  # => #<MyHandler:0x0000000163ae88 @counter=0>
666
666
  ```
667
667
 
668
+ ### source_location
669
+
670
+ Added to rufus-scheduler 3.8.0.
671
+
672
+ Returns the array `[ 'path/to/file.rb', 123 ]` like `Proc#source_location` does.
673
+
674
+ ```ruby
675
+ require 'rufus-scheduler'
676
+
677
+ scheduler = Rufus::Scheduler.new
678
+
679
+ job = scheduler.schedule_every('2h') { p Time.now }
680
+
681
+ p job.source_location
682
+ # ==> [ '/home/jmettraux/rufus-scheduler/test.rb', 6 ]
683
+
684
+ ```
685
+
668
686
  ### scheduled_at
669
687
 
670
688
  Returns the Time instance when the job got created.
671
689
 
672
690
  ```ruby
673
- job = scheduler.schedule_in('10d', :tag => 'hello') do; end
691
+ job = scheduler.schedule_in('10d', tag: 'hello') do; end
674
692
  job.scheduled_at
675
693
  # => 2013-07-17 23:48:54 +0900
676
694
  ```
@@ -773,7 +791,7 @@ job = scheduler.schedule_in('10d') do; end
773
791
  job.tags
774
792
  # => []
775
793
 
776
- job = scheduler.schedule_in('10d', :tag => 'hello') do; end
794
+ job = scheduler.schedule_in('10d', tag: 'hello') do; end
777
795
  job.tags
778
796
  # => [ 'hello' ]
779
797
  ```
@@ -842,7 +860,11 @@ require 'rufus-scheduler'
842
860
  s = Rufus::Scheduler.new
843
861
 
844
862
  def s.on_error(job, err)
845
- p [ 'error in scheduled job', job.class, job.original, err.message ]
863
+ if job
864
+ p [ 'error in scheduled job', job.class, job.original, err.message ]
865
+ else
866
+ p [ 'error while scheduling', err.message ]
867
+ end
846
868
  rescue
847
869
  p $!
848
870
  end
@@ -958,24 +980,24 @@ Here is an example:
958
980
  scheduler.at_jobs.each(&:unschedule)
959
981
  ```
960
982
 
961
- ### Scheduler#jobs(:tag / :tags => x)
983
+ ### Scheduler#jobs(tag: / tags: x)
962
984
 
963
985
  When scheduling a job, one can specify one or more tags attached to the job. These can be used to look up the job later on.
964
986
 
965
987
  ```ruby
966
- scheduler.in '10d', :tag => 'main_process' do
988
+ scheduler.in '10d', tag: 'main_process' do
967
989
  # ...
968
990
  end
969
- scheduler.in '10d', :tags => [ 'main_process', 'side_dish' ] do
991
+ scheduler.in '10d', tags: [ 'main_process', 'side_dish' ] do
970
992
  # ...
971
993
  end
972
994
 
973
995
  # ...
974
996
 
975
- jobs = scheduler.jobs(:tag => 'main_process')
997
+ jobs = scheduler.jobs(tag: 'main_process')
976
998
  # find all the jobs with the 'main_process' tag
977
999
 
978
- jobs = scheduler.jobs(:tags => [ 'main_process', 'side_dish' ]
1000
+ jobs = scheduler.jobs(tags: [ 'main_process', 'side_dish' ]
979
1001
  # find all the jobs with the 'main_process' AND 'side_dish' tags
980
1002
  ```
981
1003
 
@@ -1040,7 +1062,7 @@ Lists the work threads associated with the scheduler. The query option defaults
1040
1062
  * :active : all the work threads currently running a Job
1041
1063
  * :vacant : all the work threads currently not running a Job
1042
1064
 
1043
- Note that the main schedule thread will be returned if it is currently running a Job (ie one of those :blocking => true jobs).
1065
+ Note that the main schedule thread will be returned if it is currently running a Job (ie one of those `blocking: true` jobs).
1044
1066
 
1045
1067
  ### Scheduler#scheduled?(job_or_job_id)
1046
1068
 
@@ -1048,7 +1070,7 @@ Returns true if the arg is a currently scheduled job (see Job#scheduled?).
1048
1070
 
1049
1071
  ### Scheduler#occurrences(time0, time1)
1050
1072
 
1051
- Returns a hash ```{ job => [ t0, t1, ... ] }``` mapping jobs to their potential trigger time within the ```[ time0, time1 ]``` span.
1073
+ Returns a hash `{ job => [ t0, t1, ... ] }` mapping jobs to their potential trigger time within the `[ time0, time1 ]` span.
1052
1074
 
1053
1075
  Please note that, for interval jobs, the ```#mean_work_time``` is used, so the result is only a prediction.
1054
1076
 
@@ -1205,23 +1227,23 @@ By default, rufus-scheduler sleeps 0.300 second between every step. At each step
1205
1227
  The :frequency option lets you change that 0.300 second to something else.
1206
1228
 
1207
1229
  ```ruby
1208
- scheduler = Rufus::Scheduler.new(:frequency => 5)
1230
+ scheduler = Rufus::Scheduler.new(frequency: 5)
1209
1231
  ```
1210
1232
 
1211
1233
  It's OK to use a time string to specify the frequency.
1212
1234
 
1213
1235
  ```ruby
1214
- scheduler = Rufus::Scheduler.new(:frequency => '2h10m')
1236
+ scheduler = Rufus::Scheduler.new(frequency: '2h10m')
1215
1237
  # this scheduler will sleep 2 hours and 10 minutes between every "step"
1216
1238
  ```
1217
1239
 
1218
1240
  Use with care.
1219
1241
 
1220
- ### :lockfile => "mylockfile.txt"
1242
+ ### lockfile: "mylockfile.txt"
1221
1243
 
1222
1244
  This feature only works on OSes that support the flock (man 2 flock) call.
1223
1245
 
1224
- Starting the scheduler with ```:lockfile => ".rufus-scheduler.lock"``` will make the scheduler attempt to create and lock the file ```.rufus-scheduler.lock``` in the current working directory. If that fails, the scheduler will not start.
1246
+ Starting the scheduler with ```lockfile: '.rufus-scheduler.lock'``` will make the scheduler attempt to create and lock the file ```.rufus-scheduler.lock``` in the current working directory. If that fails, the scheduler will not start.
1225
1247
 
1226
1248
  The idea is to guarantee only one scheduler (in a group of schedulers sharing the same lockfile) is running.
1227
1249
 
@@ -1250,7 +1272,7 @@ class HostLock
1250
1272
  end
1251
1273
 
1252
1274
  scheduler =
1253
- Rufus::Scheduler.new(:scheduler_lock => HostLock.new('coffee.example.com'))
1275
+ Rufus::Scheduler.new(scheduler_lock: HostLock.new('coffee.example.com'))
1254
1276
  ```
1255
1277
 
1256
1278
  By default, the scheduler_lock is an instance of `Rufus::Scheduler::NullLock`, with a `#lock` that returns true.
@@ -1273,7 +1295,7 @@ class PingLock
1273
1295
  end
1274
1296
 
1275
1297
  scheduler =
1276
- Rufus::Scheduler.new(:trigger_lock => PingLock.new('main.example.com'))
1298
+ Rufus::Scheduler.new(trigger_lock: PingLock.new('main.example.com'))
1277
1299
  ```
1278
1300
 
1279
1301
  By default, the trigger_lock is an instance of `Rufus::Scheduler::NullLock`, with a `#lock` that always returns true.
@@ -1287,7 +1309,7 @@ In rufus-scheduler 2.x, by default, each job triggering received its own, brand
1287
1309
  One can set this maximum value when starting the scheduler.
1288
1310
 
1289
1311
  ```ruby
1290
- scheduler = Rufus::Scheduler.new(:max_work_threads => 77)
1312
+ scheduler = Rufus::Scheduler.new(max_work_threads: 77)
1291
1313
  ```
1292
1314
 
1293
1315
  It's OK to increase the :max_work_threads of a running scheduler.
@@ -1309,8 +1331,8 @@ Rufus::Scheduler.singleton.every '10s' { puts "hello, world!" }
1309
1331
  It's OK to pass initialization arguments (like :frequency or :max_work_threads) but they will only be taken into account the first time ```.singleton``` is called.
1310
1332
 
1311
1333
  ```ruby
1312
- Rufus::Scheduler.singleton(:max_work_threads => 77)
1313
- Rufus::Scheduler.singleton(:max_work_threads => 277) # no effect
1334
+ Rufus::Scheduler.singleton(max_work_threads: 77)
1335
+ Rufus::Scheduler.singleton(max_work_threads: 277) # no effect
1314
1336
  ```
1315
1337
 
1316
1338
  The ```.s``` is a shortcut for ```.singleton```.
@@ -1427,7 +1449,7 @@ Rufus::Scheduler.to_duration_hash(60)
1427
1449
  Rufus::Scheduler.to_duration_hash(62.127)
1428
1450
  # => { :m => 1, :s => 2, :ms => 127 }
1429
1451
 
1430
- Rufus::Scheduler.to_duration_hash(62.127, :drop_seconds => true)
1452
+ Rufus::Scheduler.to_duration_hash(62.127, drop_seconds: true)
1431
1453
  # => { :m => 1 }
1432
1454
  ```
1433
1455
 
@@ -1610,7 +1632,7 @@ class ScheController < ApplicationController
1610
1632
  Rails.logger.info "time flies, it's now #{Time.now}"
1611
1633
  end
1612
1634
 
1613
- render :text => "scheduled job #{job_id}"
1635
+ render text: "scheduled job #{job_id}"
1614
1636
  end
1615
1637
  end
1616
1638
  ```
@@ -1631,14 +1653,16 @@ If you don't want rufus-scheduler to trigger anything while running the Ruby on
1631
1653
 
1632
1654
  require 'rufus-scheduler'
1633
1655
 
1634
- s = Rufus::Scheduler.singleton
1656
+ return if defined?(Rails::Console) || Rails.env.test? || File.split($PROGRAM_NAME).last == 'rake'
1657
+ #
1658
+ # do not schedule when Rails is run from its console, for a test/spec, or
1659
+ # from a Rake task
1635
1660
 
1636
- return if defined?(Rails::Console) || Rails.env.test? || File.split($0).last == 'rake'
1637
1661
  # return if $PROGRAM_NAME.include?('spring')
1662
+ #
1638
1663
  # see https://github.com/jmettraux/rufus-scheduler/issues/186
1639
1664
 
1640
- # do not schedule when Rails is run from its console, for a test/spec, or
1641
- # from a Rake task
1665
+ s = Rufus::Scheduler.singleton
1642
1666
 
1643
1667
  s.every '1m' do
1644
1668
  Rails.logger.info "hello, it's #{Time.now}"
@@ -1646,6 +1670,8 @@ s.every '1m' do
1646
1670
  end
1647
1671
  ```
1648
1672
 
1673
+ (Beware later version of Rails where Spring takes care pre-running the initializers. Running `spring stop` or disabling Spring might be necessary in some cases to see changes to initializers being taken into account.)
1674
+
1649
1675
 
1650
1676
  ### rails server -d
1651
1677
 
@@ -1662,6 +1688,9 @@ These are two well crafted articles on process daemonization, please read them:
1662
1688
 
1663
1689
  If, anyway, you need something like `rails server -d`, why not try `bundle exec unicorn -D` instead? In my (limited) experience, it worked out of the box (well, had to add `gem 'unicorn'` to `Gemfile` first).
1664
1690
 
1691
+ ### executor / reloader
1692
+
1693
+ You might benefit from wraping your scheduled code in the executor or reloader. Read more here: https://guides.rubyonrails.org/threading_and_code_execution.html
1665
1694
 
1666
1695
  ## support
1667
1696
 
@@ -97,6 +97,12 @@ class Rufus::Scheduler::Job
97
97
 
98
98
  alias job_id id
99
99
 
100
+ def source_location
101
+
102
+ @callable.source_location
103
+ end
104
+ alias location source_location
105
+
100
106
  # Will fail with an ArgumentError if the job frequency is higher than
101
107
  # the scheduler frequency.
102
108
  #
@@ -25,6 +25,8 @@ class Rufus::Scheduler::RepeatJob < Rufus::Scheduler::Job
25
25
  nil
26
26
  self.last_at =
27
27
  opts[:last] || opts[:last_at] || opts[:last_in]
28
+
29
+ @resume_discard_past = nil
28
30
  end
29
31
 
30
32
  FIRSTS = [ :now, :immediately, 0 ].freeze
@@ -9,7 +9,7 @@ module Rufus; end
9
9
 
10
10
  class Rufus::Scheduler
11
11
 
12
- VERSION = '3.7.0'
12
+ VERSION = '3.8.2'
13
13
 
14
14
  EoTime = ::EtOrbi::EoTime
15
15
 
@@ -443,9 +443,14 @@ class Rufus::Scheduler
443
443
  ms = {}; mutexes.each { |k, v| ms[k] = v.locked? }
444
444
 
445
445
  stderr.puts("{ #{pre} rufus-scheduler intercepted an error:")
446
- stderr.puts(" #{pre} job:")
447
- stderr.puts(" #{pre} #{job.class} #{job.original.inspect} #{job.opts.inspect}")
448
- # TODO: eventually use a Job#detail or something like that
446
+ if job
447
+ stderr.puts(" #{pre} job:")
448
+ stderr.puts(" #{pre} #{job.class} #{job.original.inspect} #{job.opts.inspect}")
449
+ stderr.puts(" #{pre} #{job.source_location.inspect}")
450
+ # TODO: eventually use a Job#detail or something like that
451
+ else
452
+ stderr.puts(" #{pre} job: (error did not occur in a job)")
453
+ end
449
454
  stderr.puts(" #{pre} error:")
450
455
  stderr.puts(" #{pre} #{err.object_id}")
451
456
  stderr.puts(" #{pre} #{err.class}")
@@ -529,7 +534,7 @@ class Rufus::Scheduler
529
534
 
530
535
  unlock
531
536
 
532
- @thread.join
537
+ @thread.join unless @thread == Thread.current
533
538
  end
534
539
  alias stop shutdown
535
540
 
@@ -582,7 +587,7 @@ class Rufus::Scheduler
582
587
  r =
583
588
  begin
584
589
  @join_queue.pop(true)
585
- rescue ThreadError => e
590
+ rescue ThreadError
586
591
  # #<ThreadError: queue empty>
587
592
  false
588
593
  end
@@ -629,12 +634,20 @@ class Rufus::Scheduler
629
634
  Thread.new do
630
635
 
631
636
  while @started_at do
637
+ begin
638
+
639
+ unschedule_jobs
640
+ trigger_jobs unless @paused_at
641
+ timeout_jobs
632
642
 
633
- unschedule_jobs
634
- trigger_jobs unless @paused_at
635
- timeout_jobs
643
+ sleep(@frequency)
636
644
 
637
- sleep(@frequency)
645
+ rescue => err
646
+ #
647
+ # for `blocking: true` jobs mostly
648
+ #
649
+ on_error(nil, err)
650
+ end
638
651
  end
639
652
 
640
653
  rejoin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fugit