AWS SQS ActiveJob job_data argument is not being received by the ActiveJob

0

I have a rails app and I am struggling to integrate Aws::Rails::SqsActiveJob so that I can pull events from an AWS SQS Queue. I keep getting the error 'wrong number of arguments (given 0, expected 1)' when ActiveJob.perform_later is called.

Is this a serialization issue? Is the message not being serialized for ActiveJob.perform_later? Do I need a custom serializer?

Here are some of the things I have tried:

  • various function argument signatures such as a keyword job_data:
  • inheriting from ActiveJob::Base and ApplicationJob
  • using :amazon_sqs, :amazon_sqs_async and :shoryuken for config.active_job.queue_adapter
  • using both FIFO and standard SQS queues

Using these gems:

gem 'aws-sdk-rails'
ruby '2.6.6'
gem 'rails', '~> 5.2.3'

Here is the activejob class:

class CartsUpdateJob < ApplicationJob
queue_as :default

def perform(job_data)
Rails.logger.info "data: " + job_data.inspect
end
end

I know that the message payload is arriving from the SQS queue successfully because the event's json hash value of \['job_class'] is being received by the JobRunner since JobRunner knows which ActiveJob class to use to invoke perform():

File 'lib/aws/rails/sqs_active_job/job_runner.rb', line 10

def initialize(message)
@job_data = Aws::Json.load(message.data.body)
@class_name = @job_data\['job_class'].constantize
@id = @job_data\['job_id']
end

and it looks like that same payload @job_data json hash is then being sent as the argument to the perform function:

File 'lib/aws/rails/sqs_active_job/job_runner.rb', line 16

def run
ActiveJob::Base.execute @job_data
end

However I keep getting the error 'wrong number of arguments (given 0, expected 1)'.

[Aws::SQS::Client 200 7.777424 0 retries] receive_message(wait_time_seconds:20,max_number_of_messages:1,visibility_timeout:120,attribute_names:["All"],message_attribute_names:["All"],queue_url:"https://sqs.us-west-2.amazonaws.com/1111111111111/theapp-dev-queue.fifo")

\[ActiveJob] \[CheckoutsUpdateJob] Performing CheckoutsUpdateJob (Job ID: ) from AmazonSqsAsync() \[ActiveJob] \[CheckoutsUpdateJob] Error performing CheckoutsUpdateJob (Job ID: ) from AmazonSqsAsync() in 33.78ms: ArgumentError (wrong number of arguments (given 0, expected 1)): C:/Users/KG/theapp/app/jobs/checkouts_update_job.rb:2:in perform' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activejob-5.2.5/lib/active_job/execution.rb:39:in block in perform_now' ... C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activejob-5.2.5/lib/active_job/execution.rb:22:in execute' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/aws-sdk-rails-3.6.0/lib/aws/rails/sqs_active_job/job_runner.rb:17:in run' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/aws-sdk-rails-3.6.0/lib/aws/rails/sqs_active_job/executor.rb:30:in block in execute' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in run_task'

The test message is 20.56KB and here are some pertinent parts of the json that are taken from the SQS 'send and receive messages' utility:

{
"version": "0",
...
"region": "us-west-2",
"resources": [],
"detail": {
"metadata": {
...
}
},
"webhook": {
"line_items": [
...
],
"note": null,
"updated_at": "2021-04-16T00:03:52.020Z",
"created_at": "2021-04-10T00:05:43.173Z"
},
"job_class": "CartsUpdateJob"
}

I am able to simulate a successful ActiveJob handoff and processing with my business logic added back into the ActiveJob CartsUpdateJob perform_now() function and using the same test event via the console:

client = Aws::SQS::Client.new
queue_url = client.get_queue_url(queue_name: "theapp-dev-aws-queue")
resp = client.receive_message(queue_url: queue_url.queue_url)
job_data = JSON.parse(resp.messages[0].body)
CartsUpdateJob.perform_now(job_data)

but when I run that same code in the console with .perform_later:

Enqueued CartsUpdateJob (Job ID: e84635b8-75bd-462b-bd83-4606fb9cfa54) to AmazonSqs(default) with arguments: ...

I can see the same argument error in the worker process output:

8:18:51 PM aws.1 | Running job: e84635b8-75bd-462b-bd83-4606fb9cfa54\[CartsUpdateJob] 8:18:51 PM aws.1 | Running job: \[CartsUpdateJob] 8:18:51 PM aws.1 | Error processing job \[CartsUpdateJob]: wrong number of arguments (given 0, expected 1) 8:18:51 PM aws.1 | C:/Users/KG/theapp/app/jobs/carts_update_job.rb:5:in `perform'

I would greatly appreciate some help. Thank you.

gefragt vor 3 Jahren487 Aufrufe
1 Antwort
0

json message was missing the arguments key:

{
"job_class": "CartsUpdateJob",
"job_id": "aecfa167-4ddf-4e94-83bf-425f2494303f",
"provider_job_id": null,
"queue_name": "default",
"priority": null,
"arguments": [
"my-test-string"
],
"executions": 0,
"exception_executions": {},
"locale": "en",
"timezone": "UTC",
"enqueued_at": "2021-04-20T21:44:28Z"
}

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen