cloudtasker 0.15.rc1 → 0.15.rc3

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: ef70d0506e7bc1d286b1ecd2444eed28fdf39d0edb0d88a3fde7e860031efdde
4
+ data.tar.gz: da9c05f82b28ac52836db27fe722bf13729bd179e103ccbb1b62737712e53c75
5
5
  SHA512:
6
- metadata.gz: 915fb26b5107680819a63cd55d2097f56675779f160eb284e109aacbbd111af358e71e5afc99194ec1846e022a73797f57d5e7b8be7b3b2684cc3b30f0fdc787
7
- data.tar.gz: 3ca5533216e37a51b2393720d60a6a969ca9c887c0151391f9409921bc952062fd6a82855e9c21b0673a35a604ba40fa56f9f72a590e8481397388c70306ff27
6
+ metadata.gz: 1e7571d1deaa2d46cdb7082653258736a3421132badd5f21d166d9fcea11814130f42319f69cd9d1ebcbefb89ed7b12367a21c4511cc61a7accc4bf466995311
7
+ data.tar.gz: 33537a08a998a42e7d9a4e5272a4f03983894612d18afc05642e420ead7c36d6e547c142296dc39f8f286c3341afeacd46c62a4770f884e6e54c14a3f4ad9c4c
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.rc3](https://github.com/keypup-io/cloudtasker/tree/v0.15.rc3) (2025-11-17)
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.rc3)
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.rc3'
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,22 @@ 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
+ # Serialize/deserialize arguments to mimic job enqueueing and produce a similar context
145
+ job_args = JSON.parse(args.to_json)
146
+ new(job_args: job_args).execute
147
+ end
148
+
133
149
  #
134
150
  # Enqueue a worker with explicity options.
135
151
  #
@@ -184,7 +200,12 @@ module Cloudtasker
184
200
  # @return [String] The name of queue.
185
201
  #
186
202
  def job_queue
187
- (@job_queue ||= self.class.cloudtasker_options_hash[:queue] || Config::DEFAULT_JOB_QUEUE).to_s
203
+ (
204
+ @job_queue ||=
205
+ Thread.current[:cloudtasker_propagated_queue] ||
206
+ self.class.cloudtasker_options_hash[:queue] ||
207
+ Config::DEFAULT_JOB_QUEUE
208
+ ).to_s
188
209
  end
189
210
 
190
211
  #
@@ -215,7 +236,7 @@ module Cloudtasker
215
236
  #
216
237
  # Execute the worker by calling the `perform` with the args.
217
238
  #
218
- # @return [Any] The result of the perform.
239
+ # @return [Any] The result of the worker perform method.
219
240
  #
220
241
  def execute
221
242
  logger.info('Starting job...')
@@ -436,6 +457,10 @@ module Cloudtasker
436
457
  def execute_middleware_chain
437
458
  self.perform_started_at = Time.now
438
459
 
460
+ # Store the parent worker queue so as to propagate it to the child workers
461
+ # See: #job_queue
462
+ Thread.current[:cloudtasker_propagated_queue] = job_queue if self.class.cloudtasker_options_hash[:propagate_queue]
463
+
439
464
  Cloudtasker.config.server_middleware.invoke(self) do
440
465
  # Immediately abort the job if it is already dead
441
466
  flag_as_dead if job_dead?
@@ -454,6 +479,7 @@ module Cloudtasker
454
479
  end
455
480
  ensure
456
481
  self.perform_ended_at = Time.now
482
+ Thread.current[:cloudtasker_propagated_queue] = nil
457
483
  end
458
484
  end
459
485
  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.rc3
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-17 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)