Groovy-based Spring Boot task choking on configured cron - spring-boot

Not sure if this is purely a Spring Boot issue, purely a Groovy issue, or a problem arising from using Groovy to build a Spring Boot app. I have a Spring Boot background task that -- in production -- I want running once an hour:
#Component
class MyTask {
#Scheduled(cron = "${tasks.mytask.cron}")
void doSomething() {
// blah whatever
}
}
In my application.yml file I have:
logging:
config: 'logback.groovy'
server:
port: 9200
error:
whitelabel:
enabled: false
spring:
cache:
type: none
myapp:
detailsMode: ${detailsMode:Terse}
verification: 5
tasks:
mytask:
cron: '0 0/1 * 1/1 * ? *'
However for local development I want to be able to change the cron expression (for testing, etc.). When I go to compile this I get:
Expected '$tasks.mytask.cron' to be an inline constant of type java.lang.String in #org.springframework.scheduling.annotation.Scheduled
# line 31, column 23.
#Scheduled(cron = "${tasks.mytask.cron}")
Any ideas what I need to do to fix this? I need an externally-configurable value like tasks.mytask.cron that I can define in my app properties/YAML.

myapp:
detailsMode: ${detailsMode:Terse}
verification: 5
tasks:
mytask:
cron: '0 0/1 * 1/1 * ?'
or
#Scheduled(cron = '${myapp.tasks.mytask.cron}')
also notice that your cron format is incorrect

Related

Serverless Framework - unrecognized property 'params'

I am trying to create a scheduled lambda function using the Serverless framework and to send it different parameters from different events.
here is my serverless configuration:
functions:
profile:
timeout: 10
handler: profile.profile
events:
- schedule:
rate: rate(1 minute)
params:
hello: world
The issue is that when I run sls deploy, I get the following error:
Serverless: at 'functions.profile.events[0]': unrecognized property 'params'
This is basically copied from the documentation here, so should work...
Am I missing something?
The documentation you're referencing is for Apache Open Whisk.
If you're using AWS, you'll need to use input as shown in the aws documentation
functions:
aggregate:
handler: statistics.handler
events:
- schedule:
rate: rate(10 minutes)
enabled: false
input:
key1: value1
key2: value2
stageParams:
stage: dev
The documentation that you referred to is for OpenWhisk https://www.serverless.com/framework/docs/providers/openwhisk/events/schedule/#schedule/.
Cloudwatch Events (now rebranded as EventBridge) is at https://www.serverless.com/framework/docs/providers/aws/events/schedule/#enabling--disabling. Sample code for reference
functions:
aggregate:
handler: statistics.handler
events:
- schedule:
rate: rate(10 minutes)
enabled: false
input:
key1: value1
key2: value2
stageParams:
stage: dev
- schedule:
rate: cron(0 12 * * ? *)
enabled: false
inputPath: '$.stageVariables'
- schedule:
rate: rate(2 hours)
enabled: true
inputTransformer:
inputPathsMap:
eventTime: '$.time'
inputTemplate: '{"time": <eventTime>, "key1": "value1"}'
Official docs at https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduled-events.html
I could see one of my configuration something like below. There we use parameters instead of param.
functions:
test_function:
handler: handler.test_function
memorySize: 512
timeout: 60
events:
- http:
path: get-hello
method: get
request:
parameters:
queryStrings:
name: true

Creating private gke cluster

Creating private gke cluster with yaml.
Currently looking into creating a private gke. tried adding private settings in yaml file but getting error
resources:
- name: myclus
type: gcp-types/container-v1:projects.locations.clusters
properties:
parent: projects/[PROJECT_ID]/locations/[REGION]
cluster:
name: my-clus
zone: [ZONE]
network: [NETWORK]
subnetwork: [SUBNETWORK] ### leave this field blank if using the default network###
initialClusterVersion: "1.13"
nodePools:
- name: my-clus-pool1
initialNodeCount: 1
autoscaling:
enabled: true
minNodeCount: 1
maxNodeCount: 12
management:
autoUpgrade: true
autoRepair: true
config:
machineType: n1-standard-1
diskSizeGb: 15
imageType: cos
diskType: pd-ssd
oauthScopes: ###Change scope to match needs###
- https://www.googleapis.com/auth/cloud-platform
preemptible: false
Looking for it to create a private cluster with no external IPs.
Did you ever had the chance to go over this documentation?
https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters
https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters#public_master
Well, I also found this other Official Google Document that can help you achieve what you want:
https://cloud.google.com/solutions/creating-kubernetes-engine-private-clusters-with-net-proxies
On the "Creating the Docker Image" section there's a Dockerfile example.
Best of Luck!

serverless warm up plugin concurrent execution of warmup functions

I got the serverless-plugin-warmup 4.2.0-rc.1 working fine with serverless version 1.36.2
But it only executes with one single warmup call instead of the configured five.
Is there any problem in my serverless.yml config?
It is also strange that I have to add 'warmup: true' to the function section to get the function warmed up. According to the docs on https://github.com/FidelLimited/serverless-plugin-warmup the config at custom section should be enough.
plugins:
- serverless-prune-plugin
- serverless-plugin-warmup
custom:
warmup:
enabled: true
concurrency: 5
prewarm: true
schedule: rate(2 minutes)
source: { "type": "keepLambdaWarm" }
timeout: 60
functions:
myFunction:
name: ${self:service}-${opt:stage}-${opt:version}
handler: myHandler
environment:
FUNCTION_NAME: myFunction
warmup: true
in AWS Cloud Watch I only see one execution every 2 minutes. I would expect to see 5 executions every 2 minutes, or do I misunderstand something here?
EDIT:
Now using the master branch concurrency works but now the context that is deliverd to the function which should be warmed is broken: Using Spring Cloud Functions => "Error parsing Client Context as JSON"
Looking at the JS of the generated warmup function the delivered source looks not ok =>
const functions = [{"name":"myFunction","config":{"enabled":true,"source":"\"\\\"{\\\\\\\"source\\\\\\\":\\\\\\\"serverless-plugin-warmup\\\\\\\"}\\\"\"","concurrency":3}}];
Config is:
custom:
warmup:
enabled: true
concurrency: 3
prewarm: true
schedule: rate(5 minutes)
timeout: 60
Added Property sourceRaw: true to warmup config which generates a clean source in the Function JS.
const functions = [{"name":"myFunctionName","config":{"enabled":true,"source":"{\"type\":\"keepLambdaWarm\"}","concurrency":3}}];
Config:
custom:
warmup:
enabled: true
concurrency: 3
prewarm: true
schedule: rate(5 minutes)
source: { "type": "keepLambdaWarm" }
sourceRaw: true
timeout: 60

Getting exception while running SaltStack module.run function with name dsc.apply_config

I'm getting the following error while trying to state.apply sls on windows machine.
ID: ProvisionADDC
Function: module.run
Name: dsc.apply_config
Result: False
Comment: Module function dsc.apply_config threw an exception. Exception: No JSON results from powershell. Additional info follows:
retcode:
0
stderr:
stdout:
Started: 12:06:08.044000
Duration: 2684.0 ms
Changes:
Since win_dsc is execution module, then I'm forced to use state.module module to run this function on minion:
C:\DSC:
file.directory:
- makedirs: True
allprofiles:
win_firewall.disabled
CopyDSCModules:
file.recurse:
- name: 'C:\Program Files\WindowsPowerShell\Modules'
- source: salt://windows/dsc/
InstallADDomainServices:
win_servermanager.installed:
- name: AD-Domain-Services
- restart: True
- require:
- file: CopyDSCModules
ProvisionADDC:
module.run:
- name: dsc.apply_config
- path: C:\DSC\
- source: salt://windows/mof
- require:
- file: 'C:\DSC'
- file: CopyDSCModules
- win_servermanager: InstallADDomainServices
Anybody have experience with win_dsc and SaltStack ?
I think it's a case of the documentation lacking a bit, but you need to actually run the configuration in the same ps1 file, eg.
Configuration myconfig {
Node 'localhost' {
WindowsFeature 'DNS' {
Name = 'DNS'
Ensure = Present
}
}
}
myconfig
I'm playing with this a litle at the moment and hopefully I can come up with a helpful issue/PR because it is lacking a bit (even if just for better error logging).
I'm not sure how this works in terms of determining a specific config as I'e not tested that yet (using the config_name param).

spring boot cmd line cron expression java.lang.IllegalStateException

I do have an argument with my Spring Boot powered web application. I'm trying to override a #Scheduled cron expression from the command line, but spring responds with a java.lang.IllegalStateException.
Initialization of bean failed;
nested exception is java.lang.IllegalStateException:
Encountered invalid #Scheduled method 'work':
Cron expression must consist of 6 fields (found 1 in "0")
I have a Spring Component with a Scheduled Annotation:
#Scheduled(cron="${myapp.cron}")
public void work() {
...
}
There is an application.properties file like this:
myapp.cron=0 0 1 * * *
I'm bundling the application with maven to a jar file. The application runs on an ubuntu machine with Java 8 as an init task (/etc/init/myapp.conf).
description "My app"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
setuid <USER>
setgid <GROUP>
script
java -Xms2G -Xmx2G -jar /opt/myapp.jar \
--server.port=4014 \
--server.address=127.0.0.1
--logging.file=/opt/myapp.log \
--logging.level.root=INFO
end script
Until this point everything is fine. Adding the following line gives the above mention exception.
--myapp.cron=0 0 8 * * *
Any ideas? What's wrong?
Cheers,
Kai
Kai,
You're passing in the 0 0 8 * * * as command line parameter in order to get it in the Spring environment. However, your app only gets the first 0 as variable value, hence the exception about the required 6 parts. Surround the value with quotes instead:
--myapp.cron="0 0 8 * * *"
create a xyz.properties file under src/main/resouce folder.
cron.open.status.mgr.schedule=10 15 0 15 * ?
and do something like below
#Component
public class OpenStatusManagerScheduler {
#Scheduled(cron = "${open.status.mgr.schedule}")
public void scheduleStatusTaskWithCronExpression() {}
}

Resources