Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show job duration in logs [BATCH-2775] #830

Closed
spring-issuemaster opened this issue Nov 23, 2018 · 0 comments
Closed

Show job duration in logs [BATCH-2775] #830

spring-issuemaster opened this issue Nov 23, 2018 · 0 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 23, 2018

Mahmoud Ben Hassine opened BATCH-2775 and commented

As of version 4.1, calculating the job duration is possible with one of the following options:

Option 1: Using a listener

Something like:

class ExecutionTimeJobListener implements JobExecutionListener {

	private Logger logger = LoggerFactory.getLogger(ExecutionTimeJobListener.class);
	private StopWatch stopWatch = new StopWatch();

	@Override
	public void beforeJob(JobExecution jobExecution) {
		stopWatch.start();
	}

	@Override
	public void afterJob(JobExecution jobExecution) {
		stopWatch.stop();
		logger.info("Job took " + stopWatch.getTotalTimeSeconds() + "s");
	}
}

This option requires the user to write this kind of listener and register it in the job definition.

Option 2: Using the logs

This option requires to find the first and last lines of the log and calculate the difference of timestamps. For small and quick jobs, that can be easy. However, for jobs that run for hours and produce a big chunk of logs, finding the first/last lines manually and do the math can be tedious.

Both options require manual actions from the user and letting the framework do this task has an added value. The job duration to be printed in the logs is intended for humans, so it should be in a human readable format, something like: 3h 15m 45s.


Affects: 4.1.0

Referenced from: pull request #385, and commits 10f2281

Backported to: 4.2.0.M3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.