cloudtasker 0.15.rc1 → 0.15.rc2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3acbfbd2b8d2ac1c4260b01fc44c4bd43c0061db35eeb84a0bc5f4c1a9358204
4
- data.tar.gz: 1a9e2d8048b39eac16dc794671796025a16c1f27e95967adde23ad4361be3610
3
+ metadata.gz: 42cff7c50d99de1f66e83e04a3946c7cf370ce03004ee47dc7ee3dcbb46564c8
4
+ data.tar.gz: 26997c5f357a41563a074e2d03ea2724c3824b46a4b034e45b9e5573d4024cbe
5
5
  SHA512:
6
- metadata.gz: 915fb26b5107680819a63cd55d2097f56675779f160eb284e109aacbbd111af358e71e5afc99194ec1846e022a73797f57d5e7b8be7b3b2684cc3b30f0fdc787
7
- data.tar.gz: 3ca5533216e37a51b2393720d60a6a969ca9c887c0151391f9409921bc952062fd6a82855e9c21b0673a35a604ba40fa56f9f72a590e8481397388c70306ff27
6
+ metadata.gz: 0aa102da9cbc6ba0d108eb5d3be521efd954544bc7f4a47c11830401c61d2e590cbad7d7d540448dd4c41df7d11774c663c519a1b044518dc1a7c9f46c2c5906
7
+ data.tar.gz: b415391333360f336f0553297206ce725df0d617a14f3dc0a8fe8c8fb81b7ead8b9fbe92f608ba75214af0469161b2abf1aab65c9b400900a7e5b047d6ed4a18
data/.rubocop.yml CHANGED
@@ -51,6 +51,9 @@ Style/Documentation:
51
51
  - "examples/**/*"
52
52
  - "spec/**/*"
53
53
 
54
+ Style/SafeNavigationChainLength:
55
+ Enabled: false
56
+
54
57
  Metrics/ParameterLists:
55
58
  CountKeywordArgs: false
56
59
 
data/CHANGELOG.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.15.rc1](https://github.com/keypup-io/cloudtasker/tree/v0.15.rc1) (2025-10-30)
3
+ ## [v0.15.rc2](https://github.com/keypup-io/cloudtasker/tree/v0.15.rc2) (2025-11-13)
4
4
 
5
- [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.14.0...v0.15.rc1)
5
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.14.0...v0.15.rc2)
6
6
 
7
7
  **Improvements:**
8
+ - Queues: support `propagate_queue: true` option on `cloudtasker_options` to make workers enqueued inside a job use the runtime queue instead of the default (class-configured or `default`) queue.
8
9
  - Unique Jobs: add `until_completed` strategy to lock jobs until they are completed or have exhausted all retries (thanks @jam-packed).
10
+ - Workers: provide `perform_now` method to perform job inline and align with other job frameworks
9
11
 
10
12
  **Maintenance:**
11
13
  - Supported rubies: drop support for ruby `2.7`. Cloudtasker now requires ruby `3.0` and above.
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ gem 'bundler', '~> 2.0'
11
11
  gem 'rake', '>= 12.3.3'
12
12
  gem 'rspec', '~> 3.0'
13
13
  gem 'rspec-json_expectations', '~> 2.2'
14
- gem 'rubocop', '~> 1.64.1'
14
+ gem 'rubocop', '~> 1.75.2'
15
15
  gem 'rubocop-rspec', '~> 3.0.1'
16
16
  gem 'semantic_logger'
17
17
  gem 'timecop'
data/README.md CHANGED
@@ -120,6 +120,10 @@ Open a Rails console and enqueue some jobs
120
120
 
121
121
  # Process job in 60 seconds
122
122
  DummyWorker.perform_in(60, 'foo')
123
+
124
+ # Process job immediately, inline
125
+ # Supported since: v0.15.rc2
126
+ DummyWorker.perform_now('foo')
123
127
  ```
124
128
 
125
129
  Your Rails logs should display the following:
@@ -474,6 +478,11 @@ MyWorker.perform_at(3.days.from_now, arg1, arg2)
474
478
  MyWorker.schedule(args: [arg1, arg2], time_at: Time.parse('2025-01-01 00:50:00Z'), queue: 'critical')
475
479
  # or
476
480
  MyWorker.schedule(args: [arg1, arg2], time_in: 5 * 60, queue: 'critical')
481
+
482
+ # Perform worker immediately, inline. This will not send the job to
483
+ # the processing queue. Middlewares such as Unique Job, Batch Jobs will still be invoked.
484
+ # Supported since: v0.15.rc2
485
+ MyWorker.perform_now(arg1, arg2)
477
486
  ```
478
487
 
479
488
  Cloudtasker also provides a helper for re-enqueuing jobs. Re-enqueued jobs keep the same job id. Some middlewares may rely on this to track the fact that that a job didn't actually complete (e.g. Cloustasker batch). This is optional and you can always fallback to using exception management (raise an error) to retry/re-enqueue jobs.
@@ -545,6 +554,53 @@ Queues can also be assigned at runtime when scheduling a job:
545
554
  CriticalWorker.schedule(args: [1], queue: :important)
546
555
  ```
547
556
 
557
+ ### Propagating the queue in child workers
558
+ **Supported since:** `v0.15.rc2`
559
+
560
+ You can specify `propagate_queue: true` via the `cloudtasker_options` to make workers enqueued inside a job use the runtime queue instead of the default (class-configured or `default`) queue:
561
+
562
+ ```ruby
563
+ # app/workers/child_worker.rb
564
+
565
+ class ChildWorker
566
+ include Cloudtasker::Worker
567
+
568
+ cloudtasker_options queue: :level2
569
+
570
+ def perform(some_arg)
571
+ logger.info("This is a child job, which is set to run on the level2 queue by default.")
572
+ end
573
+ end
574
+ ```
575
+
576
+ ```ruby
577
+ # app/workers/parent_worker.rb
578
+
579
+ class ParentWorker
580
+ include Cloudtasker::Worker
581
+
582
+ cloudtasker_options queue: :level1, propagate_queue: true
583
+
584
+ def perform(some_arg)
585
+ logger.info("This is a parent job, which is set to run on the level1 queue by default.")
586
+
587
+ # This worker will run on queue 'level1' instead of 'level2' because
588
+ # the "propagate_queue: true" has been specified on the parent.
589
+ ChildWorker.perform_async(some_arg)
590
+
591
+ # This worker will run on queue 'level3' because the queue has been explicitly
592
+ # specified on the scheduling options. It overrides the propagate_queue behaviour.
593
+ ChildWorker.schedule(queue: 'level3', args: [some_arg])
594
+
595
+ # This worker will run on queue 'level4' and the first ChildWorker it enqueues
596
+ # will also run on queue 'level4'. The second ChidlWorker will, however, run
597
+ # on queue 'level3', as explained above.
598
+ ParentWorker.schedule(queue: 'level4', args: [some_arg])
599
+ end
600
+ end
601
+ ```
602
+
603
+
548
604
  ## Extensions
549
605
  **Note**: Extensions are not available when using cloudtasker via ActiveJob.
550
606
 
@@ -30,7 +30,7 @@ module Cloudtasker
30
30
  head :not_found
31
31
  rescue StandardError
32
32
  # 422: Job will be retried
33
- head :unprocessable_entity
33
+ head 422
34
34
  end
35
35
 
36
36
  private
@@ -66,7 +66,7 @@ module Cloudtasker
66
66
  payload = payload.merge(schedule_time: payload[:schedule_time].to_i)
67
67
 
68
68
  # Save task
69
- task = new(**payload.merge(id: id))
69
+ task = new(**payload, id: id)
70
70
  queue << task
71
71
 
72
72
  # Execute task immediately if in testing and inline mode enabled
@@ -89,7 +89,7 @@ module Cloudtasker
89
89
  # Save job
90
90
  redis.write(key(id), payload)
91
91
  redis.sadd(key, [id])
92
- new(**payload.merge(id: id))
92
+ new(**payload, id: id)
93
93
  end
94
94
 
95
95
  #
@@ -103,7 +103,7 @@ module Cloudtasker
103
103
  gid = key(id)
104
104
  return nil unless (payload = redis.fetch(gid))
105
105
 
106
- new(**payload.merge(id: id))
106
+ new(**payload, id: id)
107
107
  end
108
108
 
109
109
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudtasker
4
- VERSION = '0.15.rc1'
4
+ VERSION = '0.15.rc2'
5
5
  end
@@ -96,7 +96,7 @@ module Cloudtasker
96
96
  end
97
97
 
98
98
  #
99
- # Enqueue worker in the backgroundf.
99
+ # Enqueue worker in the background.
100
100
  #
101
101
  # @param [Array<any>] *args List of worker arguments
102
102
  #
@@ -130,6 +130,20 @@ module Cloudtasker
130
130
  schedule(args: args, time_at: time_at)
131
131
  end
132
132
 
133
+ #
134
+ # Perform a worker inline, without sending it to the queue for processing.
135
+ #
136
+ # Middlewares (unique job, batch etc.) will still be invoked as if the job
137
+ # had been scheduled.
138
+ #
139
+ # @param [Array<any>] *args List of worker arguments
140
+ #
141
+ # @return [Any] The result of the worker perform method.
142
+ #
143
+ def perform_now(*args)
144
+ new(job_args: args).execute
145
+ end
146
+
133
147
  #
134
148
  # Enqueue a worker with explicity options.
135
149
  #
@@ -184,7 +198,12 @@ module Cloudtasker
184
198
  # @return [String] The name of queue.
185
199
  #
186
200
  def job_queue
187
- (@job_queue ||= self.class.cloudtasker_options_hash[:queue] || Config::DEFAULT_JOB_QUEUE).to_s
201
+ (
202
+ @job_queue ||=
203
+ Thread.current[:cloudtasker_propagated_queue] ||
204
+ self.class.cloudtasker_options_hash[:queue] ||
205
+ Config::DEFAULT_JOB_QUEUE
206
+ ).to_s
188
207
  end
189
208
 
190
209
  #
@@ -215,7 +234,7 @@ module Cloudtasker
215
234
  #
216
235
  # Execute the worker by calling the `perform` with the args.
217
236
  #
218
- # @return [Any] The result of the perform.
237
+ # @return [Any] The result of the worker perform method.
219
238
  #
220
239
  def execute
221
240
  logger.info('Starting job...')
@@ -436,6 +455,10 @@ module Cloudtasker
436
455
  def execute_middleware_chain
437
456
  self.perform_started_at = Time.now
438
457
 
458
+ # Store the parent worker queue so as to propagate it to the child workers
459
+ # See: #job_queue
460
+ Thread.current[:cloudtasker_propagated_queue] = job_queue if self.class.cloudtasker_options_hash[:propagate_queue]
461
+
439
462
  Cloudtasker.config.server_middleware.invoke(self) do
440
463
  # Immediately abort the job if it is already dead
441
464
  flag_as_dead if job_dead?
@@ -454,6 +477,7 @@ module Cloudtasker
454
477
  end
455
478
  ensure
456
479
  self.perform_ended_at = Time.now
480
+ Thread.current[:cloudtasker_propagated_queue] = nil
457
481
  end
458
482
  end
459
483
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudtasker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.rc1
4
+ version: 0.15.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-10-30 00:00:00.000000000 Z
11
+ date: 2025-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  requirements: []
240
- rubygems_version: 3.5.22
240
+ rubygems_version: 3.5.4
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Background jobs for Ruby using Google Cloud Tasks (beta)