Trigger Error when Triggering immediate Quartz Job with Grails - exception
I am setting up a system where users can request tasks be run asynchronously.
I am storing these tasks in a table in Grails Domain Class ScheduledTask.
I have two Quartz Jobs
CheckForScheduledTasksJob
Triggered every 30 seconds
RunActionJob
Triggered on demand when needed
(In the future there will be a configurable number of these running at a time.)
Currently the code flow is:
CheckForScheduledTasksJob
CheckForScheduledTasksJob {
void execute() {
taskService.checkForScheduledTasks()
}
}
TaskService
void checkForScheduledTasks() {
ScheduledTask scheduleTask = getNextPendingTask()
if (scheduleTask) {
Map params = [ scheduleTask:scheduleTask ]
RunActionJob.triggerNow(params)
}
}
At this point I get the following error:
| Error 2014-01-02 15:00:01,112 [quartzScheduler_QuartzSchedulerThread] ERROR core.ErrorLogger - An error occurred while scanning for the next triggers to fire.
Message: Couldn't acquire next trigger: Couldn't retrieve trigger: com.mypath.RunActionJob
Line | Method
->> 2848 | acquireNextTrigger in org.quartz.impl.jdbcjobstore.JobStoreSupport
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 2759 | execute in org.quartz.impl.jdbcjobstore.JobStoreSupport$40
| 2757 | execute . . . . . . . . . in ''
| 3787 | executeInNonManagedTXLock in org.quartz.impl.jdbcjobstore.JobStoreSupport
| 2756 | acquireNextTriggers . . . in ''
^ 272 | run in org.quartz.core.QuartzSchedulerThread
Caused by JobPersistenceException: Couldn't retrieve trigger: com.mypath.RunActionJob
->> 1533 | retrieveTrigger in org.quartz.impl.jdbcjobstore.JobStoreSupport
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 2808 | acquireNextTrigger in ''
| 2759 | execute . . . . . . . . . in org.quartz.impl.jdbcjobstore.JobStoreSupport$40
| 2757 | execute in ''
| 3787 | executeInNonManagedTXLock in org.quartz.impl.jdbcjobstore.JobStoreSupport
| 2756 | acquireNextTriggers in ''
^ 272 | run . . . . . . . . . . . in org.quartz.core.QuartzSchedulerThread
The code for RunActionJob is still being developed. All it looks like so far is:
class RunActionJob implements InterruptableJob, Serializable {
boolean interrupted = false
static triggers = {
}
void execute(JobExecutionContext context) {
log.info ("HERE " + (new Date()))
ScheduledTask task = context.getMergedJobDataMap()?.scheduleTask
return
}
void interrupt() {
interrupted = true
}
}
Thanks in advance for any help or responses.
By trial and error I eventually found that the cause of this problem was passing the class ScheduledTask in the params. I think that there were serialization errors with the class.
If instead I just passed ScheduledTask.id in the params, and then converted the id to the full object in the RunActionJob, then everything started working as expected.
Related
jq: how to select entries containing element in a mixed (scalar/list) value
I need to select values that have lists with a special element in some attributes: Statement: - Effect: Allow Action: - s3:GetObject - s3:ListBucket Resource: - Fn::Join: - '' - - 'arn:aws:s3:::' - bucket* - Fn::Join: - '' - - 'arn:aws:s3:::' - bucket* - Effect: Allow Action: cloudformation:* Resource: - Fn::Join: - '' - - 'arn:aws:cloudformation:' - Ref: AWS::Region - ':' - Ref: AWS::AccountId - :stack/ - Ref: AWS::StackName - /* In this example, the first element must be selected, because its Action contains s3:GetObject. If I try to use select here, it does not work, because in the second element, Action does not contain a list, and contains can't iterate over it. $ cat action.yaml | yq -y '.Statement[].Action[]|contains("s3:GetObject") jq: error (at <stdin>:1): Cannot iterate over string ("cloudforma...) I can check if the element contains a list, using type: $ cat action.yaml | yq -y '.Resources.InstanceRolePolicy.Properties.PolicyDocument.Statement[]|select(.Action|select(type=="array"))' But how can I combine both checks in our select ?
Put select(type=="array") after traversing to an element (here .Statement[].Action ) but before trying to iterate over its items ([]): .Statement[].Action | select(type=="array")[] | contains("s3:GetObject") Demo Actually, there is a built-in shortcut to select(type=="array") called arrays, so this is equivalent: .Statement[].Action | arrays[] | contains("s3:GetObject") Demo
redis.clients.jedis.exceptions.JedisDataException: ERR Error compiling script (new function): user_script:1: malformed number near
I'm writing a lua script in redis, and execute it in spring, the content is as simple as local store = redis.call('hget',KEYS[1],'capacity') print(store) if store <= 0 then return 0 end store = store - 1 redis.call('hset',KEYS[1],'capacity',store) redis.call('sadd',KEYS[2],ARGV[1]) return 1 but when I run this script, an exception throws redis.clients.jedis.exceptions.JedisDataException: ERR Error compiling script (new function): user_script:1: malformed number near '262b4ca69c1805485d135aa6298c2b00bc7c8c09' And I tried the following script in redis-cli eval "local s = tonumber(redis.call('hget',KEYS[1],'capacity')) return s" 1 001 It returns (integer) 100 And the Java code is showing as follows: String script ="local store = redis.call('hget',KEYS[1],'capacity')\n" + "print(store)\n" + "if store <= 0\n" + "then return 0\n" + "end\n" + "store = store - 1\n" + "redis.call('hset',KEYS[1],'capacity',store)\n" + "redis.call('sadd',KEYS[2],ARGV[1])\n" + "return 1\n" + "\n"; if(sha==null){ sha = jedis.scriptLoad(script) ; System.out.println("sha:"+sha); } Object ojb = jedis.eval(sha,2,id,userName,id) ; Now I'm so confused and any help will be grateful
You want to use jedis.evalsha instead of jedis.eval. The error you are getting is Redis server trying to interpret 262b4ca69c1805485d135aa6298c2b00bc7c8c09 as an actual script. To invoke a previously loaded script you use EVALSHA command.
jq "strptime/1 is not implemented on this platform" when trying to use 'fromdate'
i run jq v1.6 on Windows 10, my input is "2009-12-20 08:00:00" and i want to get the Day of Week. my test filter is ("2009-12-20 08:00:00" | sub(" "; "T") + "Z" | fromdate | gmtime) but all i get is an error: jq: error: strptime/1 not implemented on this platform Tried so many things, but nothing worked. builtins returns the relevant functions: [ "input_line_number/0", "input_filename/0", "now/0", "localtime/0", "gmtime/0", "mktime/0", "strflocaltime/1", "strftime/1", "strptime/1", "stderr/0", "debug/0", "modulemeta/0", "get_jq_origin/0", "get_prog_origin/0", "get_search_list/0", "halt_error/1", "halt/0", "env/0", "format/1", "error/1", "max/0", "min/0", "sort/0", "nan/0", "infinite/0", "isnormal/0", "isnan/0", "isinfinite/0", "type/0", "utf8bytelength/0", "length/0", "contains/1", "has/1", "delpaths/1", "getpath/1", "setpath/2", "implode/0", "explode/0", "split/1", "rtrimstr/1", "ltrimstr/1", "endswith/1", "startswith/1", "keys_unsorted/0", "keys/0", "tostring/0", "tonumber/0", "fromjson/0", "tojson/0", "modf/0", "frexp/0", "ldexp/2", "trunc/0", "scalbln/2", "round/0", "rint/0", "nexttoward/2", "nextafter/2", "nearbyint/0", "logb/0", "log1p/0", "lgamma/0", "fmod/2", "fmin/2", "fmax/2", "fma/3", "fdim/2", "fabs/0", "expm1/0", "erfc/0", "erf/0", "copysign/2", "ceil/0", "yn/2", "jn/2", "y1/0", "y0/0", "tgamma/0", "tanh/0", "tan/0", "sqrt/0", "sinh/0", "sin/0", "remainder/2", "pow/2", "log2/0", "log10/0", "log/0", "j1/0", "j0/0", "hypot/2", "floor/0", "exp2/0", "exp/0", "cosh/0", "cos/0", "cbrt/0", "atanh/0", "atan2/2", "atan/0", "asinh/0", "asin/0", "acosh/0", "acos/0", "empty/0", "not/0", "path/1", "range/2", "halt_error/0", "error/0", "map/1", "select/1", "sort_by/1", "group_by/1", "unique/0", "unique_by/1", "max_by/1", "min_by/1", "add/0", "del/1", "map_values/1", "recurse/1", "recurse/2", "recurse/0", "recurse_down/0", "to_entries/0", "from_entries/0", "with_entries/1", "reverse/0", "indices/1", "index/1", "rindex/1", "paths/0", "paths/1", "any/2", "any/1", "any/0", "all/2", "all/1", "all/0", "isfinite/0", "arrays/0", "objects/0", "iterables/0", "booleans/0", "numbers/0", "normals/0", "finites/0", "strings/0", "nulls/0", "values/0", "scalars/0", "scalars_or_empty/0", "leaf_paths/0", "join/1", "flatten/1", "flatten/0", "range/1", "fromdateiso8601/0", "todateiso8601/0", "fromdate/0", "todate/0", "match/2", "match/1", "test/2", "test/1", "capture/2", "capture/1", "scan/1", "splits/2", "splits/1", "split/2", "sub/2", "sub/3", "gsub/3", "gsub/2", "range/3", "while/2", "until/2", "limit/2", "isempty/1", "first/1", "last/1", "nth/2", "first/0", "last/0", "nth/1", "combinations/0", "combinations/1", "transpose/0", "in/1", "inside/1", "input/0", "repeat/1", "inputs/0", "ascii_downcase/0", "ascii_upcase/0", "truncate_stream/1", "fromstream/1", "tostream/0", "bsearch/1", "walk/1", "INDEX/2", "INDEX/1", "JOIN/2", "JOIN/3", "JOIN/4", "IN/1", "IN/2", "drem/2", "exp10/0", "gamma/0", "pow10/0", "scalb/2", "significand/0", "lgamma_r/0", "builtins/0" ]
Here are two alternatives for solving the problem on a Windows 10 machine: Install Linux for Windows Then, once jq has been installed (e.g. using linuxbrew), you could use this filter: "2009-12-20 08:00:00" | strptime("%Y-%m-%d %T") | strftime("%a") It yields "Sun" (which is correct :-) Use Zeller's congruence # Use Zeller's Congruence to determine the day of the week, given # year, month and day as integers in the conventional way. # Emit 0 for Saturday, 1 for Sunday, etc. # def day_of_week($year; $month; $day): if $month == 1 or $month == 2 then [$month + 12, $year - 1] else [$month, $year] end | $day + (13*(.[0] + 1)/5|floor) + (.[1]%100) + ((.[1]%100)/4|floor) + (.[1]/400|floor) - 2*(.[1]/100|floor) | . % 7 ; "2009-12-20 08:00:00" | capture("(?<Y>\\d+)-(?<m>\\d+)-(?<d>\\d+)") | map_values(tonumber) | day_of_week(.Y; .m; .d) This yields 1, signifying Sunday.
Assign puppet Hash to hieradata yaml
I want to assign a hash variable from puppet to a hiera data structure but i only get a string. Here is a example to illustrate, what I want. Finaly I don't want to access a fact. 1 --- 2 filesystems: 3 - partitions: "%{::partitions}" And here is my debug code: 1 $filesystemsarray = lookup('filesystems',Array,'deep',[]) 2 $filesystems = $filesystemsarray.map | $fs | { 3 notice("fs: ${fs['partitions']}") 4 } 5 6 notice("sda1: ${filesystemsarray[0]['partitions']['/dev/sda1']}") The map leads to the following output: Notice: Scope(Class[Profile::App::Kms]): fs: {"/dev/mapper/localhost--vg-root"=>{"filesystem"=>"ext4", "mount"=>"/", "size"=>"19.02 GiB", "size_bytes"=>20422066176, "uuid"=>"02e2ba2c-2ee4-411d-ac63-fc963c8026b4"}, "/dev/mapper/localhost--vg-swap_1"=>{"filesystem"=>"swap", "size"=>"512.00 MiB", "size_bytes"=>536870912, "uuid"=>"95ba4b2a-7434-48fd-9331-66443c752a9e"}, "/dev/sda1"=>{"filesystem"=>"ext2", "mount"=>"/boot", "partuuid"=>"de90a5ed-01", "size"=>"487.00 MiB", "size_bytes"=>510656512, "uuid"=>"398f2ab6-a7e8-4983-bd81-db03984fbd0e"}, "/dev/sda2"=>{"size"=>"1.00 KiB", "size_bytes"=>1024}, "/dev/sda5"=>{"filesystem"=>"LVM2_member", "partuuid"=>"de90a5ed-05", "size"=>"19.52 GiB", "size_bytes"=>20961034240, "uuid"=>"wLKRQm-9bdn-mHA8-M8bE-NL76-Gmas-L7Gp0J"}} Seem to be a Hash as expected but the notice in Line 6 leads to: Error: Evaluation Error: A substring operation does not accept a String as a character index. Expected an Integer at ... What's my fault?
Why is RestClient throwing null pointer exception when trying to post a JSON data to a restful web service?
I am trying to use the RESTClient class to do a post to a RESTful web service. I am getting an NPE at setBody in groovyx.net.http.HTTPBuilder$RequestConfigDelegate. My code is postParam = [ sourceAccountNo : fundTransfer.fromAccount.accountNumber, sourceBankCode : fundTransfer.fromAccount.bank.bankCode, destinationBankCode : fundTransfer.toAccount.bank.bankCode, destinationBankAccountNo: fundTransfer.toAccount.accountNumber, amount : fundTransfer.amount, narrationOne : fundTransfer.note, uniqueId : fundTransfer.uniqueId ] String balanceTransferURL = ApplicationProperty.propertiesMap.get(ApplicationProperty.PropertyKey.BULK_BALANCE_TRANSFER_URL) def restClient = new RESTClient(balanceTransferURL) def restResponse = restClient.post(requestContentType:JSON,body:postParam) My error log is as follows message: null Line | Method ->> 1200 | setBody in groovyx.net.http.HTTPBuilder$RequestConfigDelegate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 1111 | setPropertiesFromMap in '' | 946 | <init> . . . . . . . . . . in '' | 140 | post in groovyx.net.http.RESTClient What is exactly missing? What am I doing wrong?
I ran into this same issue and figured out that it goes away when you add the requestContentType parameter: import static groovyx.net.http.ContentType.JSON requestContentType:JSON