cloudtasker 0.6.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +5 -0
  4. data/.travis.yml +3 -3
  5. data/CHANGELOG.md +38 -0
  6. data/README.md +142 -26
  7. data/_config.yml +1 -0
  8. data/app/controllers/cloudtasker/worker_controller.rb +21 -5
  9. data/cloudtasker.gemspec +2 -2
  10. data/docs/BATCH_JOBS.md +29 -4
  11. data/docs/CRON_JOBS.md +18 -14
  12. data/exe/cloudtasker +13 -1
  13. data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +26 -9
  14. data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +26 -9
  15. data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +27 -10
  16. data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +26 -9
  17. data/gemfiles/rails_5.2.gemfile.lock +26 -9
  18. data/gemfiles/rails_6.0.gemfile.lock +27 -10
  19. data/lib/cloudtasker.rb +0 -1
  20. data/lib/cloudtasker/backend/google_cloud_task.rb +65 -12
  21. data/lib/cloudtasker/backend/memory_task.rb +5 -3
  22. data/lib/cloudtasker/backend/redis_task.rb +24 -13
  23. data/lib/cloudtasker/batch/batch_progress.rb +11 -2
  24. data/lib/cloudtasker/batch/job.rb +18 -4
  25. data/lib/cloudtasker/cli.rb +6 -5
  26. data/lib/cloudtasker/cloud_task.rb +4 -2
  27. data/lib/cloudtasker/config.rb +30 -9
  28. data/lib/cloudtasker/cron/job.rb +2 -2
  29. data/lib/cloudtasker/cron/schedule.rb +26 -14
  30. data/lib/cloudtasker/local_server.rb +44 -22
  31. data/lib/cloudtasker/redis_client.rb +10 -7
  32. data/lib/cloudtasker/unique_job/job.rb +2 -2
  33. data/lib/cloudtasker/version.rb +1 -1
  34. data/lib/cloudtasker/worker.rb +46 -10
  35. data/lib/cloudtasker/worker_handler.rb +7 -5
  36. data/lib/cloudtasker/worker_logger.rb +1 -1
  37. data/lib/cloudtasker/worker_wrapper.rb +52 -0
  38. data/lib/tasks/setup_queue.rake +12 -2
  39. metadata +6 -6
  40. data/Gemfile.lock +0 -280
  41. data/lib/cloudtasker/railtie.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8721e878a098657f0c3974670df6373c873d1df2fa1042b97d9b37d7a1118299
4
- data.tar.gz: ffd5652b0220a833f603682fdb4392a850b13b185bd7516dd170f5314d1b4af6
3
+ metadata.gz: a91675f06c63076ac2e197a1279839713eca290c41ad010b26fafb67e0700327
4
+ data.tar.gz: d3826037921062db28923142541f1b89d9e1b2384270d54231d1309f7edc7c5d
5
5
  SHA512:
6
- metadata.gz: f0f98ff0e0062b28be192f8353363a736f5cb315eb14f86f577586de070127642d123617e8e831dea84271cada640ea3b9ec642ea75f3f9a12cd494432b9e178
7
- data.tar.gz: a04500924970efdbc0ceb9364314e0426c92800a4c571b839432de5b9f2faa04e678a67186b0dfd2b32222e8d8606e39ce51b0922ba9687ea827271174dcb23d
6
+ metadata.gz: 55daf715a52f5b1624a17771f0cab64c8241f30dde8abe6189782cb0abb7dc218039994740d66c04592688936febbf0067891cc67262657bf4eb7e6f914878c7
7
+ data.tar.gz: 9db2298e6189825b01646a291cd5ad0c134a533e5dd2039c1c44e68286a3aa0dd725d4f494bf58af2f8b7a0703c151ea4a27ce292ddcc9b8d20238853387092f
data/.gitignore CHANGED
@@ -12,5 +12,8 @@
12
12
  /spec/dummy/tmp/
13
13
  /tmp/
14
14
 
15
+ # Ignore lock files (e.g. Gemfile.lock)
16
+ *.lock
17
+
15
18
  # rspec failure tracking
16
19
  .rspec_status
data/.rubocop.yml CHANGED
@@ -1,5 +1,10 @@
1
1
  require: rubocop-rspec
2
2
 
3
+ AllCops:
4
+ Exclude:
5
+ - 'gemfiles/vendor/**/*'
6
+ - 'vendor/**/*'
7
+
3
8
  Metrics/ClassLength:
4
9
  Max: 150
5
10
 
data/.travis.yml CHANGED
@@ -2,11 +2,11 @@
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.3
6
- - 2.4
7
5
  - 2.5.5
6
+ services:
7
+ - redis-server
8
8
  before_install: gem install bundler -v 2.0.2
9
- before_script: rubocop
9
+ before_script: bundle exec rubocop
10
10
  gemfile:
11
11
  - gemfiles/google_cloud_tasks_1.0.gemfile
12
12
  - gemfiles/google_cloud_tasks_1.1.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.9.0](https://github.com/keypup-io/cloudtasker/tree/v0.8.2) (2020-01-23)
4
+
5
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.8.2...v0.9.0)
6
+
7
+ **Fixed bugs:**
8
+ - Cloud Task: Base64 encode task body to support UTF-8 characters (e.g. emojis).
9
+ - Redis: Restrict to one connection (class level) to avoid too many DNS lookups
10
+
11
+ **Migration**
12
+ For Sinatra applications please update your Cloudtasker controller according to [this diff](https://github.com/keypup-io/cloudtasker/commit/311fa8f9beec91fbae012164a25b2ee6e261a2e4#diff-c2a0ea6c6e6c31c749d2e1acdc574f0f).
13
+
14
+ ## [v0.8.2](https://github.com/keypup-io/cloudtasker/tree/v0.8.2) (2019-12-05)
15
+
16
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.8.1...v0.8.2)
17
+
18
+ **Fixed bugs:**
19
+ - Config: do not add processor host to `Rails.application.config.hosts` if originally empty.
20
+
21
+ ## [v0.8.1](https://github.com/keypup-io/cloudtasker/tree/v0.8.1) (2019-12-03)
22
+
23
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.8.0...v0.8.1)
24
+
25
+ **Fixed bugs:**
26
+ - Local dev server: ensure job queue name is kept when taks is retried
27
+ - Rails/Controller: bypass Rails munge logic to preserve nil values inside job arguments.
28
+
29
+ ## [v0.8.0](https://github.com/keypup-io/cloudtasker/tree/v0.8.0) (2019-11-27)
30
+
31
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.7.0...v0.8.0)
32
+
33
+ ## [v0.7.0](https://github.com/keypup-io/cloudtasker/tree/v0.7.0) (2019-11-25)
34
+
35
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.6.0...v0.7.0)
36
+
37
+ ## [v0.6.0](https://github.com/keypup-io/cloudtasker/tree/v0.6.0) (2019-11-25)
38
+
39
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.5.0...v0.6.0)
40
+
3
41
  ## [v0.5.0](https://github.com/keypup-io/cloudtasker/tree/v0.5.0) (2019-11-25)
4
42
 
5
43
  [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.4.0...v0.5.0)
data/README.md CHANGED
@@ -1,14 +1,16 @@
1
+ [![Build Status](https://travis-ci.org/keypup-io/cloudtasker.svg?branch=master)](https://travis-ci.org/keypup-io/cloudtasker) [![Gem Version](https://badge.fury.io/rb/cloudtasker.svg)](https://badge.fury.io/rb/cloudtasker)
2
+
1
3
  # Cloudtasker
2
4
 
3
5
  Background jobs for Ruby using Google Cloud Tasks.
4
6
 
5
7
  Cloudtasker provides an easy to manage interface to Google Cloud Tasks for background job processing. Workers can be defined programmatically using the Cloudtasker DSL and enqueued for processing using a simple to use API.
6
8
 
7
- Cloudtasker is particularly suited for serverless applications only responding to HTTP requests and where running a dedicated job processing is not an option (e.g. deploy via [Cloud Run](https://cloud.google.com/run)). All jobs enqueued in Cloud Tasks via Cloudtasker eventually gets processed by your application via HTTP requests.
9
+ Cloudtasker is particularly suited for serverless applications only responding to HTTP requests and where running a dedicated job processing is not an option (e.g. deploy via [Cloud Run](https://cloud.google.com/run)). All jobs enqueued in Cloud Tasks via Cloudtasker eventually get processed by your application via HTTP requests.
8
10
 
9
11
  Cloudtasker also provides optional modules for running [cron jobs](docs/CRON_JOBS.md), [batch jobs](docs/BATCH_JOBS.md) and [unique jobs](docs/UNIQUE_JOBS.md).
10
12
 
11
- A local processing server is also available in development. This local server processes jobs in lieu of Cloud Tasks and allow you to work offline.
13
+ A local processing server is also available in development. This local server processes jobs in lieu of Cloud Tasks and allows you to work offline.
12
14
 
13
15
  ## Summary
14
16
 
@@ -18,18 +20,21 @@ A local processing server is also available in development. This local server pr
18
20
  1. [Cloud Tasks authentication & permissions](#cloud-tasks-authentication--permissions)
19
21
  2. [Cloudtasker initializer](#cloudtasker-initializer)
20
22
  4. [Enqueuing jobs](#enqueuing-jobs)
21
- 5. [Extensions](#extensions)
22
- 6. [Working locally](#working-locally)
23
+ 5. [Managing worker queues](#managing-worker-queues)
24
+ 1. [Creating queues](#creating-queues)
25
+ 2. [Assigning queues to workers](#assigning-queues-to-workers)
26
+ 6. [Extensions](#extensions)
27
+ 7. [Working locally](#working-locally)
23
28
  1. [Option 1: Cloudtasker local server](#option-1-cloudtasker-local-server)
24
29
  2. [Option 2: Using ngrok](#option-2-using-ngrok)
25
- 7. [Logging](#logging)
30
+ 8. [Logging](#logging)
26
31
  1. [Configuring a logger](#configuring-a-logger)
27
32
  2. [Logging context](#logging-context)
28
- 8. [Error Handling](#error-handling)
33
+ 9. [Error Handling](#error-handling)
29
34
  1. [HTTP Error codes](#http-error-codes)
30
35
  2. [Error callbacks](#error-callbacks)
31
36
  3. [Max retries](#max-retries)
32
- 9. [Best practices building workers](#best-practices-building-workers)
37
+ 10. [Best practices building workers](#best-practices-building-workers)
33
38
 
34
39
  ## Installation
35
40
 
@@ -104,7 +109,7 @@ Open a Rails console and enqueue some jobs
104
109
  DummyWorker.perform_async('foo')
105
110
 
106
111
  # Process job in 60 seconds
107
- DummyWorker.perform_in(10, 'foo')
112
+ DummyWorker.perform_in(60, 'foo')
108
113
  ```
109
114
 
110
115
  Your Rails logs should display the following:
@@ -157,13 +162,31 @@ Cloudtasker.configure do |config|
157
162
  # config.secret = 'some-long-token'
158
163
 
159
164
  #
160
- # Specify the details of your Google Cloud Task queue.
165
+ # Specify the details of your Google Cloud Task location.
161
166
  #
162
167
  # This not required in development using the Cloudtasker local server.
163
168
  #
164
169
  config.gcp_location_id = 'us-central1' # defaults to 'us-east1'
165
170
  config.gcp_project_id = 'my-gcp-project'
166
- config.gcp_queue_id = 'my-queue'
171
+
172
+ #
173
+ # Specify the namespace for your Cloud Task queues.
174
+ #
175
+ # The gem assumes that a least a default queue named 'my-app-default'
176
+ # exists in Cloud Tasks. You can create this default queue using the
177
+ # gcloud SDK or via the `rake cloudtasker:setup_queue` task if you use Rails.
178
+ #
179
+ # Workers can be scheduled on different queues. The name of the queue
180
+ # in Cloud Tasks is always assumed to be prefixed with the prefix below.
181
+ #
182
+ # E.g.
183
+ # Setting `cloudtasker_options queue: 'critical'` on a worker means that
184
+ # the worker will be pushed to 'my-app-critical' in Cloud Tasks.
185
+ #
186
+ # Specific queues can be created in Cloud Tasks using the gcloud SDK or
187
+ # via the `rake cloudtasker:setup_queue name=<queue_name>` task.
188
+ #
189
+ config.gcp_queue_prefix = 'my-app'
167
190
 
168
191
  #
169
192
  # Specify the publicly accessible host for your application
@@ -215,7 +238,7 @@ Cloudtasker.configure do |config|
215
238
  end
216
239
  ```
217
240
 
218
- If your queue does not exist in Cloud Tasks you should [create it using the gcloud sdk](https://cloud.google.com/tasks/docs/creating-queues).
241
+ If the default queue `<gcp_queue_prefix>-default` does not exist in Cloud Tasks you should [create it using the gcloud sdk](https://cloud.google.com/tasks/docs/creating-queues).
219
242
 
220
243
  Alternatively with Rails you can simply run the following rake task if you have queue admin permissions (`cloudtasks.queues.get` and `cloudtasks.queues.create`).
221
244
  ```bash
@@ -235,10 +258,15 @@ MyWorker.perform_in(5 * 60, arg1, arg2)
235
258
  # or with Rails
236
259
  MyWorker.perform_in(5.minutes, arg1, arg2)
237
260
 
238
- # Worker will be processed on specific date
261
+ # Worker will be processed on a specific date
239
262
  MyWorker.perform_at(Time.parse('2025-01-01 00:50:00Z'), arg1, arg2)
240
263
  # also with Rails
241
264
  MyWorker.perform_at(3.days.from_now, arg1, arg2)
265
+
266
+ # With all options, including which queue to run the worker on.
267
+ MyWorker.schedule(args: [arg1, arg2], time_at: Time.parse('2025-01-01 00:50:00Z'), queue: 'critical')
268
+ # or
269
+ MyWorker.schedule(args: [arg1, arg2], time_in: 5 * 60, queue: 'critical')
242
270
  ```
243
271
 
244
272
  Cloudtasker also provides a helper for re-enqueuing jobs. Re-enqueued jobs keep the same worker 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.
@@ -262,6 +290,52 @@ class FetchResourceWorker
262
290
  end
263
291
  ```
264
292
 
293
+ ## Managing worker queues
294
+
295
+ Cloudtasker allows you to manage several queues and distribute workers across them based on job priority. By default jobs are pushed to the `default` queue, which is `<gcp_queue_prefix>-default` in Cloud Tasks.
296
+
297
+ ### Creating queues
298
+
299
+ More queues can be created using the gcloud sdk or the `cloudtasker:setup_queue` rake task.
300
+
301
+ E.g. Create a `critical` queue with a concurrency of 5 via the gcloud SDK
302
+ ```bash
303
+ gcloud tasks queues create <gcp_queue_prefix>-critical --max-concurrent-dispatches=5
304
+ ```
305
+
306
+ E.g. Create a `real-time` queue with a concurrency of 15 via the rake task (Rails only)
307
+ ```bash
308
+ rake cloudtasker:setup_queue name=real-time concurrency=15
309
+ ```
310
+
311
+ When running the Cloudtasker local processing server, you can specify the concurrency for each queue using:
312
+ ```bash
313
+ cloudtasker -q critical,5 -q important,4 -q default,3
314
+ ```
315
+
316
+ ### Assigning queues to workers
317
+
318
+ Queues can be assigned to workers via the `cloudtasker_options` directive on the worker class:
319
+
320
+ ```ruby
321
+ # app/workers/critical_worker.rb
322
+
323
+ class CriticalWorker
324
+ include Cloudtasker::Worker
325
+
326
+ cloudtasker_options queue: :critical
327
+
328
+ def perform(some_arg)
329
+ logger.info("This is a critical job run with arg=#{some_arg}.")
330
+ end
331
+ end
332
+ ```
333
+
334
+ Queues can also be assigned at runtime when scheduling a job:
335
+ ```ruby
336
+ CriticalWorker.schedule(args: [1], queue: :important)
337
+ ```
338
+
265
339
  ## Extensions
266
340
  Cloudtasker comes with three optional features:
267
341
  - Cron Jobs [[docs](docs/CRON_JOBS.md)]: Run jobs at fixed intervals.
@@ -277,7 +351,7 @@ When working locally on your application it is usually not possible to have a pu
277
351
  ### Option 1: Cloudtasker local server
278
352
  The Cloudtasker local server is a ruby daemon that looks for jobs pushed to Redis and sends them to your application via HTTP POST requests. The server mimics the way Google Cloud Tasks works, but locally!
279
353
 
280
- You can configure your applicatiion to use the Cloudtasker local server using the following initializer:
354
+ You can configure your application to use the Cloudtasker local server using the following initializer:
281
355
  ```ruby
282
356
  # config/initializers/cloudtasker.rb
283
357
 
@@ -293,23 +367,26 @@ end
293
367
 
294
368
  The Cloudtasker server can then be started using:
295
369
  ```bash
296
- cloudtasker
297
- # or
298
370
  bundle exec cloudtasker
299
371
  ```
300
372
 
301
373
  You can as well define a Procfile to manage the cloudtasker process via foreman. Then use `foreman start` to launch both your Rails server and the Cloudtasker local server.
302
374
  ```yaml
303
375
  # Procfile
304
- web: rails s
305
- worker: cloudtasker
376
+ web: bundle exec rails s
377
+ worker: bundle exec cloudtasker
378
+ ```
379
+
380
+ Note that the local development server runs with `5` concurrent threads by default. You can tune the number of threads per queue by running `cloudtasker` the following options:
381
+ ```bash
382
+ bundle exec cloudtasker -q critical,5 -q important,4 -q default,3
306
383
  ```
307
384
 
308
385
  ### Option 2: Using ngrok
309
386
 
310
387
  Want to test your application end to end with Google Cloud Task? Then [ngrok](https://ngrok.io) is the way to go.
311
388
 
312
- First start your ngrok tunnel and take note of the :
389
+ First start your ngrok tunnel:
313
390
  ```bash
314
391
  ngrok http 3000
315
392
  ```
@@ -320,9 +397,9 @@ Take note of your ngrok domain and configure Cloudtasker to use Google Cloud Tas
320
397
 
321
398
  Cloudtasker.configure do |config|
322
399
  # Specify your Google Cloud Task queue configuration
323
- # config.gcp_location_id = 'us-central1'
324
- # config.gcp_project_id = 'my-gcp-project'
325
- # config.gcp_queue_id = 'my-queue'
400
+ config.gcp_location_id = 'us-central1'
401
+ config.gcp_project_id = 'my-gcp-project'
402
+ config.gcp_queue_prefix = 'my-app'
326
403
 
327
404
  # Use your ngrok domain as the processor host
328
405
  config.processor_host = 'https://your-tunnel-id.ngrok.io'
@@ -334,7 +411,7 @@ end
334
411
 
335
412
  Finally start Rails to accept jobs from Google Cloud Tasks
336
413
  ```bash
337
- rails s
414
+ bundle exec rails s
338
415
  ```
339
416
 
340
417
  ## Logging
@@ -343,7 +420,7 @@ There are several options available to configure logging and logging context.
343
420
  ### Configuring a logger
344
421
  Cloudtasker uses `Rails.logger` if Rails is available and falls back on a plain ruby logger `Logger.new(STDOUT)` if not.
345
422
 
346
- It is also possible to configure your own logger. For example you can setup Cloudtasker with [semantic_logger](http://rocketjob.github.io/semantic_logger) by doing the following your initializer:
423
+ It is also possible to configure your own logger. For example you can setup Cloudtasker with [semantic_logger](http://rocketjob.github.io/semantic_logger) by doing the following in your initializer:
347
424
  ```ruby
348
425
  # config/initializers/cloudtasker.rb
349
426
 
@@ -389,7 +466,7 @@ Cloudtasker::WorkerLogger.log_context_processor = lambda { |worker|
389
466
  }
390
467
  ```
391
468
 
392
- You could also decide to log all available context (including arguments passed to perform) for specific workers only:
469
+ You could also decide to log all available context - including arguments passed to `perform` - for specific workers only:
393
470
  ```ruby
394
471
  # app/workers/full_context_worker.rb
395
472
 
@@ -404,7 +481,7 @@ class FullContextWorker
404
481
  end
405
482
  ```
406
483
 
407
- See the [Cloudtasker::Worker class](blob/master/lib/cloudtasker/worker.rb) for more information on attributes available to be logged in your `log_context_processor` proc.
484
+ See the [Cloudtasker::Worker class](lib/cloudtasker/worker.rb) for more information on attributes available to be logged in your `log_context_processor` proc.
408
485
 
409
486
  ## Error Handling
410
487
 
@@ -536,7 +613,7 @@ MyWorker.new.perform({ 'foo' => 'bar', 'baz' => { 'key' => 'value' } })
536
613
  ```
537
614
 
538
615
  ### Be careful with default arguments
539
- Default arguments passed to the `perform` method are not actually considered as job arguments. Default arguments will therefore be ignored in contextual logging and by extensions relying on arguments such as the `unique-job` extension.
616
+ Default arguments passed to the `perform` method are not actually considered as job arguments. Default arguments will therefore be ignored in contextual logging and by extensions relying on arguments such as the [unique job](docs/UNIQUE_JOBS.md) extension.
540
617
 
541
618
  Consider the following worker:
542
619
  ```ruby
@@ -587,6 +664,45 @@ Rails.cache.write(payload_id, data)
587
664
  BigPayloadWorker.perform_async(payload_id)
588
665
  ```
589
666
 
667
+ ### Sizing the concurrency of your queues
668
+
669
+ When defining the max concurrency of your queues (`max_concurrent_dispatches` in Cloud Tasks) you must keep in mind the maximum number of threads that your application provides. Otherwise your application threads may eventually get exhausted and your users will experience outages if all your web threads are busy running jobs.
670
+
671
+ #### With server based applications
672
+
673
+ Let's consider an application deployed in production with 3 instances, each having `RAILS_MAX_THREADS` set to `20`. This gives us a total of `60` threads available.
674
+
675
+ Now let's say that we distribute jobs across two queues: `default` and `critical`. We can set the concurrency of each queue depending on the profile of the application:
676
+
677
+ E.g. 1: The application serves requests from web users and runs backgrounds jobs in a balanced way
678
+ ```
679
+ concurrency for default queue: 20
680
+ concurrency for critical queue: 10
681
+
682
+ Total threads consumed by jobs at most: 30
683
+ Total threads always available to web users at worst: 30
684
+ ```
685
+
686
+ E.g. 2: The application is a micro-service API heavily focused on running jobs (e.g. data processing)
687
+ ```
688
+ concurrency for default queue: 35
689
+ concurrency for critical queue: 15
690
+
691
+ Total threads consumed by jobs at most: 50
692
+ Total threads always available to API clients at worst: 10
693
+ ```
694
+
695
+ Also always ensure that your total number of threads does not exceed the available number of database connections (if you use any).
696
+
697
+ #### With serverless applications
698
+
699
+ In a serverless context your application will be scaled up/down based on traffic. When we say 'traffic' this includes requests from Cloud Tasks to run jobs.
700
+
701
+ Because your application is auto-scaled - and assuming you haven't set a maximum - your job processing capacity if theoretically unlimited. The main limiting factor in a serverless context becomes external constraints such as the number of database connections available.
702
+
703
+ To size the concurrency of your queues you should therefore take the most limiting factor - which is often the database connection pool size of relational databases - and use the calculations of the previous section with this limiting factor as the capping parameter instead of threads.
704
+
705
+
590
706
  ## Development
591
707
 
592
708
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-slate
@@ -16,11 +16,6 @@ module Cloudtasker
16
16
  # Run a worker from a Cloud Task payload
17
17
  #
18
18
  def run
19
- # Build payload
20
- payload = request.params
21
- .slice(:worker, :job_id, :job_args, :job_meta)
22
- .merge(job_retries: job_retries)
23
-
24
19
  # Process payload
25
20
  WorkerHandler.execute_from_payload!(payload)
26
21
  head :no_content
@@ -39,6 +34,27 @@ module Cloudtasker
39
34
 
40
35
  private
41
36
 
37
+ #
38
+ # Parse the request body and return the actual job
39
+ # payload.
40
+ #
41
+ # @return [Hash] The job payload
42
+ #
43
+ def payload
44
+ @payload ||= begin
45
+ # Get raw body
46
+ content = request.body.read
47
+
48
+ # Decode content if the body is Base64 encoded
49
+ if request.headers[Cloudtasker::Config::ENCODING_HEADER].to_s.downcase == 'base64'
50
+ content = Base64.decode64(content)
51
+ end
52
+
53
+ # Return content parsed as JSON and add job retries count
54
+ JSON.parse(content).merge(job_retries: job_retries)
55
+ end
56
+ end
57
+
42
58
  #
43
59
  # Extract the number of times this task failed at runtime.
44
60
  #
data/cloudtasker.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Arnaud Lachaume']
11
11
  spec.email = ['arnaud.lachaume@keypup.io']
12
12
 
13
- spec.summary = 'Background jobs for Ruby using Google Cloud Tasks (alpha)'
14
- spec.description = 'Background jobs for Ruby using Google Cloud Tasks (alpha)'
13
+ spec.summary = 'Background jobs for Ruby using Google Cloud Tasks (beta)'
14
+ spec.description = 'Background jobs for Ruby using Google Cloud Tasks (beta)'
15
15
  spec.homepage = 'https://github.com/keypup-io/cloudtasker'
16
16
  spec.license = 'MIT'
17
17