cloudtasker 0.12.rc10 → 0.12.2
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 +4 -4
- data/.github/workflows/test.yml +1 -5
- data/CHANGELOG.md +44 -3
- data/README.md +56 -6
- data/app/controllers/cloudtasker/worker_controller.rb +4 -1
- data/docs/BATCH_JOBS.md +2 -2
- data/docs/CRON_JOBS.md +39 -0
- data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +135 -125
- data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +135 -125
- data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +135 -125
- data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +135 -125
- data/gemfiles/rails_5.2.gemfile.lock +78 -68
- data/gemfiles/rails_6.0.gemfile.lock +79 -69
- data/lib/cloudtasker/config.rb +26 -2
- data/lib/cloudtasker/local_server.rb +1 -1
- data/lib/cloudtasker/version.rb +1 -1
- data/lib/cloudtasker/worker.rb +1 -1
- data/lib/cloudtasker/worker_handler.rb +2 -0
- data/lib/cloudtasker.rb +1 -0
- metadata +7 -8
- data/app/controllers/cloudtasker/application_controller.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d051d238265fe5c1b1e48203c121e7284a26340026ff481e4c6240703de073b
|
4
|
+
data.tar.gz: bb785d5f8f7834bb1ef885c9bb939a43925e933c34abcf94a9609b292813b03d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81926768a084ba79aff1ae466f7dc2a11ac883c0b57f6fd41787dbedf3434d0979762158728c4548217bd06b0df2692e8bffe8cbd3d02bda447336610d4de2c0
|
7
|
+
data.tar.gz: 1ce88e8633716f8ea379affd0ef7c705ec7fc48ebdd100c0e6f525fd0e5ca61ac4f3349dde3c53ee7815e23761dbd8cfa9e1d6d2f0b1e80f9892d1b92065c61b
|
data/.github/workflows/test.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,48 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## [v0.12.2](https://github.com/keypup-io/cloudtasker/tree/v0.12.2) (2021-12-31)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.
|
5
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.12.1...v0.12.2)
|
6
|
+
|
7
|
+
**Fixed bugs:**
|
8
|
+
- Local server: Fix race condition on thread processing. See [#46](https://github.com/keypup-io/cloudtasker/pull/46)
|
9
|
+
- Non-Rails: Fix `arguments_missing?` check for non-rails projects.
|
10
|
+
|
11
|
+
## [v0.12.1](https://github.com/keypup-io/cloudtasker/tree/v0.12.1) (2021-08-25)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.12.0...v0.12.1)
|
14
|
+
|
15
|
+
**Fixed bugs:**
|
16
|
+
- Dependencies: Require `try` from `activesupport`. This was preventing non-Rails projects from properly running Cloudtasker jobs.
|
17
|
+
- WorkerController: remove useless inheritance from local ApplicationController. The parent controller was not always loaded on Rails 5 which in turn created issues with authenticity token. Fixes [#40](https://github.com/keypup-io/cloudtasker/issues/40)
|
18
|
+
|
19
|
+
## [v0.11.1](https://github.com/keypup-io/cloudtasker/tree/v0.11.1) (2021-08-25)
|
20
|
+
|
21
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.11.0...v0.11.1)
|
22
|
+
|
23
|
+
**Fixed bugs:**
|
24
|
+
- Dependencies: Require `try` from `activesupport`. This was preventing non-Rails projects from properly running Cloudtasker jobs.
|
25
|
+
- WorkerController: remove useless inheritance from local ApplicationController. The parent controller was not always loaded on Rails 5 which in turn created issues with authenticity token. Fixes [#40](https://github.com/keypup-io/cloudtasker/issues/40)
|
26
|
+
|
27
|
+
## [v0.10.2](https://github.com/keypup-io/cloudtasker/tree/v0.10.2) (2021-08-25)
|
28
|
+
|
29
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.10.1...v0.10.2)
|
30
|
+
|
31
|
+
**Fixed bugs:**
|
32
|
+
- Dependencies: Require `try` from `activesupport`. This was preventing non-Rails projects from properly running Cloudtasker jobs.
|
33
|
+
- WorkerController: remove useless inheritance from local ApplicationController. The parent controller was not always loaded on Rails 5 which in turn created issues with authenticity token. Fixes [#40](https://github.com/keypup-io/cloudtasker/issues/40)
|
34
|
+
|
35
|
+
## [v0.9.5](https://github.com/keypup-io/cloudtasker/tree/v0.9.5) (2021-08-25)
|
36
|
+
|
37
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.9.4...v0.9.5)
|
38
|
+
|
39
|
+
**Fixed bugs:**
|
40
|
+
- Dependencies: Require `try` from `activesupport`. This was preventing non-Rails projects from properly running Cloudtasker jobs.
|
41
|
+
- WorkerController: remove useless inheritance from local ApplicationController. The parent controller was not always loaded on Rails 5 which in turn created issues with authenticity token. Fixes [#40](https://github.com/keypup-io/cloudtasker/issues/40)
|
42
|
+
|
43
|
+
## [v0.12.0](https://github.com/keypup-io/cloudtasker/tree/v0.12.0) (2021-08-19)
|
44
|
+
|
45
|
+
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.11.0...v0.12.0)
|
6
46
|
|
7
47
|
**Improvements:**
|
8
48
|
- ActiveJob: do not double log errors (ActiveJob has its own error logging)
|
@@ -12,6 +52,7 @@
|
|
12
52
|
- Batch redis usage: cleanup batches as they get completed or become dead to avoid excessive redis usage with large batches.
|
13
53
|
- Batch expansion: Inject `parent_batch` in jobs. Can be used to expand the parent batch the job is in.
|
14
54
|
- Configuration: allow configuration of Cloud Tasks `dispatch deadline` at global and worker level
|
55
|
+
- Configuration: allow specifying global `on_error` and `on_dead` callbacks for error reporting
|
15
56
|
- Cron jobs: Use Redis Sets instead of key pattern matching for resource listing
|
16
57
|
- Error logging: Use worker logger so as to include context (job args etc.)
|
17
58
|
- Error logging: Do not log exception and stack trace separately, combine them instead.
|
@@ -24,7 +65,7 @@
|
|
24
65
|
**Fixed bugs:**
|
25
66
|
- Retries: Enforce job retry limit on job processing. There was an edge case where jobs could be retried indefinitely on batch callback errors.
|
26
67
|
|
27
|
-
## [v0.11.0](https://github.com/keypup-io/cloudtasker/tree/v0.11.0) (
|
68
|
+
## [v0.11.0](https://github.com/keypup-io/cloudtasker/tree/v0.11.0) (2020-11-23)
|
28
69
|
|
29
70
|
[Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.10.0...v0.11.0)
|
30
71
|
|
data/README.md
CHANGED
@@ -35,9 +35,10 @@ A local processing server is also available for development. This local server p
|
|
35
35
|
2. [Logging context](#logging-context)
|
36
36
|
9. [Error Handling](#error-handling)
|
37
37
|
1. [HTTP Error codes](#http-error-codes)
|
38
|
-
2. [
|
39
|
-
3. [
|
40
|
-
4. [
|
38
|
+
2. [Worker callbacks](#worker-callbacks)
|
39
|
+
3. [Global callbacks](#global-callbacks)
|
40
|
+
4. [Max retries](#max-retries)
|
41
|
+
5. [Dispatch deadline](#dispatch-deadline)
|
41
42
|
10. [Testing](#testing)
|
42
43
|
1. [Test helper setup](#test-helper-setup)
|
43
44
|
2. [In-memory queues](#in-memory-queues)
|
@@ -364,11 +365,41 @@ Cloudtasker.configure do |config|
|
|
364
365
|
# This option can also be configured on a per worker basis via
|
365
366
|
# the cloudtasker_options directive.
|
366
367
|
#
|
367
|
-
# Supported since: v0.12.
|
368
|
+
# Supported since: v0.12.0
|
368
369
|
#
|
369
370
|
# Default: 600 seconds (10 minutes)
|
370
371
|
#
|
371
372
|
# config.dispatch_deadline = 600
|
373
|
+
|
374
|
+
#
|
375
|
+
# Specify a proc to be invoked every time a job fails due to a runtime
|
376
|
+
# error.
|
377
|
+
#
|
378
|
+
# This hook is not invoked for DeadWorkerError. See on_dead instead.
|
379
|
+
#
|
380
|
+
# This is useful when you need to apply general exception handling, such
|
381
|
+
# as reporting errors to a third-party service like Rollbar or Bugsnag.
|
382
|
+
#
|
383
|
+
# Note: the worker argument might be nil, such as when InvalidWorkerError is raised.
|
384
|
+
#
|
385
|
+
# Supported since: v0.12.0
|
386
|
+
#
|
387
|
+
# Default: no operation
|
388
|
+
#
|
389
|
+
# config.on_error = ->(error, worker) { Rollbar.error(error) }
|
390
|
+
|
391
|
+
#
|
392
|
+
# Specify a proc to be invoked every time a job dies due to too many
|
393
|
+
# retries.
|
394
|
+
#
|
395
|
+
# This is useful when you need to apply general exception handling, such
|
396
|
+
# logging specific messages/context when a job dies.
|
397
|
+
#
|
398
|
+
# Supported since: v0.12.0
|
399
|
+
#
|
400
|
+
# Default: no operation
|
401
|
+
#
|
402
|
+
# config.on_dead = ->(error, worker) { Rollbar.error(error) }
|
372
403
|
end
|
373
404
|
```
|
374
405
|
|
@@ -649,7 +680,7 @@ Jobs failing will automatically return the following HTTP error code to Cloud Ta
|
|
649
680
|
| 404 | The job has specified an incorrect worker class. |
|
650
681
|
| 422 | An error happened during the execution of the worker (`perform` method) |
|
651
682
|
|
652
|
-
###
|
683
|
+
### Worker callbacks
|
653
684
|
|
654
685
|
Workers can implement the `on_error(error)` and `on_dead(error)` callbacks to do things when a job fails during its execution:
|
655
686
|
|
@@ -677,6 +708,25 @@ class HandleErrorWorker
|
|
677
708
|
end
|
678
709
|
```
|
679
710
|
|
711
|
+
### Global callbacks
|
712
|
+
**Supported since**: `0.12.0`
|
713
|
+
|
714
|
+
If you need to apply general exception handling logic to your workers you can specify `on_error` and `on_dead` hooks in the Cloudtasker configuration.
|
715
|
+
|
716
|
+
This is useful if you need to report errors to third-party services such as Rollbar or Bugsnag.
|
717
|
+
|
718
|
+
```ruby
|
719
|
+
# config/initializers/cloudtasker.rb
|
720
|
+
|
721
|
+
Cloudtasker.configure do |config|
|
722
|
+
#
|
723
|
+
# Report runtime and dead worker errors to Rollbar
|
724
|
+
#
|
725
|
+
config.on_error = -> (error, _worker) { Rollbar.error(error) }
|
726
|
+
config.on_dead = -> (error, _worker) { Rollbar.error(error) }
|
727
|
+
end
|
728
|
+
```
|
729
|
+
|
680
730
|
### Max retries
|
681
731
|
|
682
732
|
By default jobs are retried 25 times - using an exponential backoff - before being declared dead. This number of retries can be customized locally on workers and/or globally via the Cloudtasker initializer.
|
@@ -740,7 +790,7 @@ end
|
|
740
790
|
```
|
741
791
|
|
742
792
|
### Dispatch deadline
|
743
|
-
**Supported since**: `0.12.
|
793
|
+
**Supported since**: `0.12.0`
|
744
794
|
|
745
795
|
By default Cloud Tasks will automatically timeout your jobs after 10 minutes, independently of your server HTTP timeout configuration.
|
746
796
|
|
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
module Cloudtasker
|
4
4
|
# Handle execution of workers
|
5
|
-
class WorkerController <
|
5
|
+
class WorkerController < ActionController::Base
|
6
|
+
# No need for CSRF verification on API endpoints
|
7
|
+
skip_before_action :verify_authenticity_token
|
8
|
+
|
6
9
|
# Authenticate all requests.
|
7
10
|
before_action :authenticate!
|
8
11
|
|
data/docs/BATCH_JOBS.md
CHANGED
@@ -48,7 +48,7 @@ end
|
|
48
48
|
```
|
49
49
|
|
50
50
|
## Example: Expanding the parent batch
|
51
|
-
**Note**: `parent_batch` is available since `0.12.
|
51
|
+
**Note**: `parent_batch` is available since `0.12.0`
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
# All the jobs will be attached to the top parent batch.
|
@@ -123,7 +123,7 @@ def on_batch_node_complete(_child_job)
|
|
123
123
|
end
|
124
124
|
```
|
125
125
|
|
126
|
-
**Since:** `v0.12.
|
126
|
+
**Since:** `v0.12.0`
|
127
127
|
By default the `progress` method only considers the direct child jobs to evaluate the batch progress. You can pass `depth: somenumber` to the `progress` method to calculate the actual batch progress in a more granular way. Be careful however that this method recursively calculates progress on the sub-batches and is therefore expensive.
|
128
128
|
|
129
129
|
E.g.
|
data/docs/CRON_JOBS.md
CHANGED
@@ -65,3 +65,42 @@ if File.exist?(schedule_file) && !Rails.env.test?
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
+
## Limitations
|
69
|
+
GCP Cloud Tasks does not allow tasks to be scheduled more than 30 days (720h) in the future. Cron schedules should therefore be limited to 30 days intervals at most.
|
70
|
+
|
71
|
+
If you need to schedule a job to run on a monthly basis (e.g. on the first of the month), schedule this job to run every day then add the following logic in your job:
|
72
|
+
```ruby
|
73
|
+
#
|
74
|
+
# Cron schedule (8am UTC every day): 0 8 * * *
|
75
|
+
#
|
76
|
+
class MyMonthlyWorker
|
77
|
+
include Cloudtasker::Worker
|
78
|
+
|
79
|
+
def perform(*args)
|
80
|
+
# Abort unless we're the first of the month
|
81
|
+
return unless Time.current.day == 1
|
82
|
+
|
83
|
+
# ... job logic
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
The same approach can be used to schedule a job every quarter.
|
89
|
+
```ruby
|
90
|
+
#
|
91
|
+
# Cron schedule (8am UTC every day): 0 8 * * *
|
92
|
+
#
|
93
|
+
class MyQuarterlyWorker
|
94
|
+
include Cloudtasker::Worker
|
95
|
+
|
96
|
+
def perform(*args)
|
97
|
+
# Abort unless we're the first month of a quarter (Jan, Apr, Jul, Oct)
|
98
|
+
return unless Time.current.month == 1
|
99
|
+
|
100
|
+
# Abort unless we're the first of the month
|
101
|
+
return unless Time.current.day == 1
|
102
|
+
|
103
|
+
# ... job logic
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|