Create cron job on Google Cloud with custom name - node.js

Reading the docs for the Nodejs Scheduler I did not found how to pass a name for the cron job I want to create.
Does anyone know if this package supports this?
I tried:
> const job = {
> httpTarget: {
> uri: `my_url`,
> httpMethod: 'GET',
> },
> schedule: '0 0,8-17 * * 0-6',
> timeZone: 'my_timezone',
> body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
> name: 'custom_name'
> };

From looking at the API spec for the Cloud Scheduler Job resource and at the Nodejs Quickstart I think you need to move the body attribute within the httpTarget as the Job resource does not have a body attribute, it should be associated with the http request.
Based on your code you would end wanting something like this:
const job = {
httpTarget: {
uri: 'my_url',
httpMethod: 'GET',
body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
},
schedule: '0 0,8-17 * * 0-6',
timeZone: 'my_timezone',
name: 'custom_name'
};

I figured out what was wrong in order to set the name correctly we need to set the name with the project_id and the location_id
httpTarget: {
uri: 'my_url',
httpMethod: 'GET',
},
schedule: '0 0,8-17 * * 0-6',
timeZone: 'my_timezone',
name: 'projects/YOUR_PROJECT_ID/locations/YOUR_LOCATION_ID/jobs/YOUR_CUSTOM_JOB_NAME'
};

Related

Artillery return 404 for target url

I have an artillery config setup to test two different versions of my API gateway (Apollo federated Graphql gateway). The V2 gateway URL returns 404 with artillery, but from the browser and Postman, it is accessible. I am quite confused as to why this is the case. What could be the issue here? The V1 URL of the gateway is accessible by artillery, but when it hits the V2 URL, it returns a 404. Here is my config file
config:
environments:
v2:
target: "https://v2.com/graphql" # not accessible by artillery but works with postman and browser
phases:
- duration: 60
arrivalRate: 5
name: Warm up
- duration: 120
arrivalRate: 5
rampTo: 50
name: Ramp up load
- duration: 300
arrivalRate: 50
name: Sustained load
v1:
target: "https://v1.com/graphql" # accessible by artillery and other agents
phases:
- duration: 60
arrivalRate: 5
name: Warm up
- duration: 120
arrivalRate: 5
rampTo: 50
name: Ramp up load
payload:
path: "test-user.csv"
skipHeader: true
fields:
- "email"
- "_id"
-
path: "test-campaign.csv"
skipHeader: true
fields:
- "campaignId"
scenarios:
- name: "Test"
flow:
- post:
url: "/"
headers:
Authorization: Bearer <token>
json:
query: |
query Query {
randomQuery {
... on Error {
message
statusCode
}
... on Response {
res {
__typename
}
}
Any help would be appreciated. Thank you.

Errno 20 Not a directory: '/tmp/tmp6db1q_sn/pyproject.toml/egg-info'

I'm wrapping my colleague's code in an AWS SAM. I made a lambda to just call existing code with a run method which I did like this.
import json
from sentance_analyser_v2.main import run
def lambda_handler(event, context):
if (event['path'] == '/analyse'):
return RunAnalyser(event, context)
else:
return {
"statusCode": 200,
"body": json.dumps({
"message": "Hello"
}),
}
def RunAnalyser(event, context):
source = event['queryStringParameters']['source']
output = run(source)
return {
"statusCode": 200,
"body": json.dumps({
"output": json.dumps(output)
})
}
After running into numerous package problems I realized I forget to use the sam build --use-container command and I was hoping after a build it would solve some of my package errors but I ran into this error code -
Error: PythonPipBuilder:ResolveDependencies - [Errno 20] Not a directory: '/tmp/tmp6db1q_sn/pyproject.toml/egg-info'
After trying to understand what the freak that even is I started pulling my hairs out because there is nothing on this...
Here is the basic template that I currently use just so I can test that my wrapping worked. I'm still very new to AWS & SAM so I don't want to overcomplicate things just yet with the template.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
Globals:
Function:
Timeout: 30
Tracing: Active
Api:
TracingEnabled: True
Resources:
MainLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: main_lambda/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
Analyser:
Type: Api
Properties:
Path: /analyse
Method: get
Outputs:
HelloEfsApi:
Description: "API Gateway endpoint URL for Prod stage for Hello EFS function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"

Moodle Web Service responses with invalid_parameter_exception

I created moodle and mariadb containers with Docker.
Moodle: 3.11.4
Mariadb: 10.3
I am trying following webservice to execute:
client:
wwwroot: 'http://localhost:8012',
service: 'moodle_mobile_app',
token: '8faf4879d2c654f11e404095032ae382',
strictSSL: true
call:
curl "http://localhost:8012/webservice/rest/server.php?wstoken=8faf4879d2c654f11e404095032ae382&moodlewsrestformat=json&wsfunction=core_user_get_users_by_field&moodlewsrestformat=json&id=2"
but getting follwing error:
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter",
"message":"Invalid parameter value detected (Missing required key in single structure:field)",
"debuginfo":"Missing required key in single structure: field"
}
I tried it same with moodle client for node
... client.call({ wsfunction: "core_user_get_users_by_field", method: "POST", args: { id: 2 } })...
but also receiving same error.
I checked API documentation and id is valid parameter for this
webservice.
Can you please help?
Issue is resolved
client.call({
method: "POST",
wsfunction: "core_user_get_users_by_field",
args: {
field: "id",
values: ["2"]
}
}).then(function(info) {
var str = JSON.stringify(info, null, 4);
console.log(str);
});

Node js swagger response description

i have developed a REST Service using Node Js and Express.
I have integrate Swagger to define api doc.
About login service this is the swagger definition that i used:
/**
* #swagger
* /api/v1.0/login:
* post:
* tags:
* - Login
* description: Login into system
* produces:
* - application/json
* parameters:
* - username: User
* description: The username of user
* in: body
* required: true
* - password: password
* description: Password of user
* in: body
* required: true
*
* responses:
* 200:
* description: Successfully login
*/
But my service gives me this response json:
{
"status": "ok",
"data": {
"auth": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjViYzg3ZDFkOWNhNmRkNDM5MDI1YjA1MCIsImlhdCI6MTU0MTA5MzMxMSwiZXhwIjoxNTQxMTc5NzExfQ.3BIl0dIQg-cEU9fyM7BocKLHEugH8cws5_E-dmRVHZM",
"faId": "HSo7q2o0",
"roles": "Owner"
}
}
How i can describe this response into swagger response description?
Thanks
You can learn a lot about how to format Swagger definitions using the actual specification online: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responsesDefinitionsObject
A really simplified version of what you want would look something like this:
responses:
200:
description: Successfully login
schema:
properties:
status:
type: string
data:
type: object
properties:
auth:
type: boolean
token:
type: string
faId:
type: string
roles:
type: string
You would probably want to fill in more information as far as descriptions, which properties are required, etc. You can read about what those mean in the link above.
Also, models in Swagger are defined using the JSON Schema vocabulary, which you can read more about here.

swagger post body without schema

I am using node-swagger. It's working fine. I want to post json body without defining the schema in details. For example below I don't want to specify object properties. Is there any way to do this?
/pets:
post:
description: Add new
parameters:
- name: id
in: body
description: data to post
required: true
type: object
responses:
'200':
description: A list of pets
schema:
type : string
It's not rendering the textarea to post json data.
Try this YAML:
---
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
paths:
/:
post:
produces:
- application/json
parameters:
- in: body
name: id
required: true
schema:
"$ref": "#/definitions/inBody"
responses:
201:
description: Added
definitions:
inBody:
type: object
If you are using swagger-ui-express and swagger-jsdoc and don't wan to use definitions you can directly define in YAML on endpoint like this.
/**
* #swagger
* /pets:
* post:
* description: Add new
* produces:
* - application/json
* parameters:
* - name: id
* description: data to post
* in: body
* required: true
* schema:
* type: object
* responses:
* 201:
* description: Pet created
*/
Based on Open API 3 spec, for an empty body request, you should have a requestBody section like the following:
requestBody:
required: true
description: blabla.
content:
application/json:
schema:
type: object
nullable: true

Resources