In a project I use spring-batch, as a part of cleanup for processes that stuck I use
JobExplorer.findRunningJobExecutions(...)
but that function return empty set. After digging I found next problem: spring-batch use SQL like
SELECT E.JOB_EXECUTION_ID, ... from %PREFIX%JOB_EXECUTION E ... WHERE ... E.END_TIME is NULL .... After running long job, I got that from beginning 3 Dates in %PREFIX%JOB_EXECUTION (CREATE_TIME, START_TIME, END_TIME) have same value. This mean that SQL will always return empty set.
Question is, am I one who get this?
How to report bug to Spring team?
Here is the link to the Spring batch project home page
Jira's can be Entered here
Not sure what version you are running, but with version 2.1.1 (which is real old I know) but this code works.
jobOperator.getRunningExecutions(String jobName)
Here is the javadoc from that version
/**
* Get the id values of all the running {#link JobExecution JobExecutions}
* with the given job name.
*
* #param jobName the name of the job to search under
* #return the id values of the running {#link JobExecution} instances
* #throws NoSuchJobException if there are no {#link JobExecution
* JobExecutions} with that job name
*/
Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException;
Link to the most update JobOperator
Hope this helps.
Related
I've got a SpringBoot Scheduler that looks like this:
#Scheduled(cron = "*/10 * * * * * ") // Every 10 seconds
public void scheduleTaskUsingCronExpression() {
long now = System.currentTimeMillis() / 1000;
System.out.println("schedule tasks using cron jobs - " + now);
}
I'd like to get the time of the next event, so I can print it out at the end of each event. I've read about using CronExpression, which has a next() method, but not sure how I get the CronExpression. OR do I create a CronExpression and somehow pass it in instead of using the #Scheduled annotation?
I'm not sure I can get accurate interval time but I can get roughly correct next running time from following code.
#Value("${cron.schedule}") String schedule;
#Scheduled(cron = "${cron.schedule}") // Every 10 seconds
public void scheduleTaskUsingCronExpression() {
var expression = CronExpression.parse(schedule);
var result = expression.next(LocalDateTime.now());
System.out.println("schedule tasks using cron jobs - " + result);
}
You can define your cron string (that you use in the #Scheduled annotation) as a final field of your class, and then create CronExpression from it to find out the next trigger date.
Also, instead of using #Scheduled annotation, you can take a look at Spring's TaskScheduler (from the package org.springframework.scheduling). It has the method TaskScheduler#schedule with two arguments: a Runnable that will run in background and a CronTrigger to set the cron expression and and the timezone of executing background tasks.
UPD. One other way to reuse your cron is set it in your application.properties and use within #Value and #Scheduled annotations, e.g. #Scheduled(cron = ${property.from.file}). In this case you can also change the cron expression before running your application if needed.
I have a table called JobSchedular
JobSchedular
JobCode
JobName
JobDescription
FunctionName
Status
RunInterval(CronEcpression)
Job001
Notify
To Send Notification
SendNotification
ACTIVE
0 * * * * ?
Job002
Appointment
To manage appointment
ManageAppointment
ACTIVE
0 * * * * ?
My Requirement is to Create Schedular on SPring Boot using #Scheduled annotation
which takes list of rows from tables and call the function dynamically based on corn expression
Now spring boot has built in support to quartz. Use this example to schedule job.
https://www.callicoder.com/spring-boot-quartz-scheduler-email-scheduling-example/
I'm modeling one entity that has a prepare-release workflow. So in addition to the ordinary POST action to create the entity, I also have a second POST custom operation to set it active. This triggers considerable backend activity which is why I implement it as a custom operation and not as a simple update on a property (PUT).
So far so good, however in the API interface documentation, it still describes the operation as "create a xxx resource", which is false. I found no way to change this description. How can I put a different text there?
actually figured out from a totally unrelated post (https://stackoverflow.com/a/49534635/982364) that this works:
* collectionOperations={"post", "special"={
* "method"="PUT",
* "path"="/myentity/{id}/commit",
* "controller"=EntitySpecial::class,
* "denormalization_context"={"groups"={"myentity_commit"}},
* "swagger_context" = {
* "summary" = "commit to this action"
* },
* "defaults"={"_api_receive"=false}
* }},
I have been banging my head for 5 hours and I finally solved the problem but I just cannot go to sleep without knowing the reason. Let me explain the issue first.
I have used codeigniter HMVC extension and installed ion_auth as a separate module.
|-modules
|--auth
|---config
|-----ion_auth.php
|---controllers
|-----auth.php
|---models
|-----ion_auth_model.php
|---views
When I was trying to get a user's group I started to get wired SQL errors. Then I narrowed the issue and figured out that the items in config/ion_auth.php were not loaded in the ion_auth_model.php file.
ERROR - 2016-02-24 20:09:26 --> Query error: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'as id, .name,
.description JOIN ON .=.id WHERE . = '2'' at line 1 - Invalid
query: SELECT . as id, .name, .description JOIN ON .=.id
WHERE . = '2'
Then I tried couple of stuffs and when I remove the index 'ion_auth' from
couple of method calls in ion_auth_model.php everything started to work.
I changed
$this->tables = $this->config->item('tables', 'ion_auth');
$this->join = $this->config->item('join', 'ion_auth);
to
$this->tables = $this->config->item('tables');
$this->join = $this->config->item('join');
Can anyone tell me why it worked?
This is the inner implementation of the CodeIgniter function config->item() found in the file system\core\Config.php
/**
* Fetch a config file item
*
* #param string $item Config item name
* #param string $index Index name
* #return string|null The configuration item or NULL if the item doesn't exist
*/
public function item($item, $index = '')
{
if ($index == '')
{
return isset($this->config[$item]) ? $this->config[$item] : NULL;
}
return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL;
}
When you pass the $index parameter, the function checks if both parameters are initialized in the config and returns config[$index] of the CI instance; or null if any of them is not initialized.
If config[$item] is not set in the CI instance, the function returns always null. Let's assume this is not the case, as your call don't crash when avoiding $index.
So when you pass $index as the second parameter, your code crashes because the function returns null, and that means that the config[$index] of the CI instance is not set. Now the question is why it's not set, and I can't help you here, but it looks like you are missing to load some modules.
Best regards
I am using Laravel 3 in one project and it's been a joy. I have also looked at the source code several times to see how some things work behind the scenes.
But now in Laravel 4, I don't know where to begin or how to understand it all. Where can I learn all the behind the scenes of Laravel 4?
Case in point: I wanted to find out if the DB::insert() returns the id of inserted row. So I started searching.
1. I found the Illuminate\Support\Facades\Facade class that "encapsulates" DB.
2. The resolveFacadeInstance function is called and then I tried to print these arrays, but my computer hangs :-/. And I'm sure this would lead to many more classes that I wouldn't understand.
Is there a way I could try to learn the inner workings of Laravel 4? Maybe stack traces?
The facade class is just a filter class to allow you to call methods as if they were static.
For the facade mappings go here: http://laravel.com/docs/facades#facade-class-reference
The starting point to fully understand laravel's inner-workings should begin at:
/public/index.php
You can follow the logic of the program, noticing that requires start.php, which loads an instance of the "Application" which is found here:
/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
This Tuts+ video shows a couple of ways of finding out what class is actually doing the work.
E.g.:
$root = get_class(DB::getFacadeRoot());
var_dump($root);
You can check out the early docs for Laravel 4 here : http://four.laravel.com/ – that should give you a good starting point
The actual Laravel 4 code is well documented in the files. If you want to understand the inner workings then open up the source code files and read the notes. For example I looked up the DB::insert() code in /vendor/laravel/framework/src/Illuminate/Foundation/Application.php.
/**
* Run an insert statement against the database.
*
* #param string $query
* #param array $bindings
* #return bool
*/
public function insert($query, $bindings = array())
{
return $this->statement($query, $bindings);
}
Ok, so this is calling the statement function so I search for function statement in the same code / class:
/**
* Execute an SQL statement and return the boolean result.
*
* #param string $query
* #param array $bindings
* #return bool
*/
public function statement($query, $bindings = array())
{
return $this->run($query, $bindings, function($me, $query, $bindings)
{
if ($me->pretending()) return true;
$bindings = $me->prepareBindings($bindings);
return $me->getPdo()->prepare($query)->execute($bindings);
});
}
We can now see that this returns the boolean result based on the comments above the code.
If you come from Laravel 3 this article is for you. After that you should read the other tutorials of that series.
Author's note:
This article should outline some of the more important changes to Laravel between versions 3 and the upcoming version 4. Bear in mind
this isn’t all of the changes. As the release of Laravel 4 gets closer
I’ll keep this article up to date. If you’re having any problems with
Laravel 4 please jump on to #laravel on Freenode. At this time we’d
like to ask people not to post help topics on the forums.