Extbase: scheduler cannot load a class - scheduled-tasks

I have a scheduler (extension "scheduler" 6.2.0) task class:
namespace MyVendor\MyExt\Scheduler;
class MultiStepProcessTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
public function execute() {
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$businessLogic = $objectManager->get(\MyVendor\MyExt\Scheduler\MultiStepProcessTaskBusinessLogic::class);
return $businessLogic->run();
}
}
And a class implementing business logic for the scheduler task:
namespace MyVendor\MyExt\Scheduler;
class MultiStepProcessTaskBusinessLogic {
public function run() {
...
}
}
I created a scheduler task in BE. If I run it manually - it's OK. If it is started automatically - following error message comes:
[scheduler]: Task failed to execute successfully. Class:
MyVendor\MyExt\Scheduler\MultiStepProcessTask, UID: 8. Could not
analyse class:
MyVendor\MyExt\Scheduler\MultiStepProcessTaskBusinessLogic maybe not
loaded or no autoloader? (msg#4.0.255)
The best is - after being once run manually, the task runs automatically without errors until the cache is cleared. After that it needs one manual run again.
One more strange thing: in the main scheduler task class (MultiStepProcessTask) no injection is possible. That's why I had to create business logic object via objectManager

The best solution would be to write a command controller based on extbase. There you can use the ObjectManager and you can run it directly from CLI and of course also call it via scheduler!

Related

spring Batch process is running automatically even with the spring.batch.job.enabled=false flag

My Goal : Prevent batch Job from lunching while project startup.
I want to run a batch job from spring boot project once in every one hour using #scheduled annotation. However the job is starting as soon as I run the project....
spring.batch.job.enabled=false
#Scheduled( cron = "* * */1 * * *")
public void jobScheduled(){
logger.info("Job triggered");
getAllFileNames().stream().forEach( fileName-> {
jobRunner.runFlatFileBatchJob(fileName);
});
}
I have declared my class like below
#Configuration
#EnableScheduling
public class JobScheduler {
#Autowired
public JobScheduler(JobRunner jobRunner){
logger.info("job scheduler created... ");
this.jobRunner = jobRunner;
}
The Job is starting as soon as Run the application. I want it to wait till the project loads completely and other integration objects prepare themselves.
Thanks in advance.
Santrupta Dash

Retry attribute is not working as expected - NUnit Framework

We are using C# Selenium and NUnit framework for our test automation. Sometimes some test cases will fail in dev environment during execution due environmental issues. I was trying to re-run the failed ones, by using Retry attribute. But it didn't work ( I have kept assertion failures as well)
Could you please have a look the below code
[TestFixture]
public class UITests : BaseClassProtractor
{
[SetUp]
public void Setup()
{
//**Call chrome driver and open app url set up**//
}
[Test]
[Retry(1)]
public TestMethod1()
{
//** Write test Steps
}
[TearDown]
public void TearDown()
{
Drivers.TryRemove(TestContext.CurrentContext.Test.FullName, out var localDriver);
localDriver?.Quit();
}
}
Thanks,
Khaja Shaik.
[Retry(1)] indicates that the test should only be run once! That is, it won't be retried if it fails. Use [Retry(2)] as a minimum.
If you continue to get failures, we need to see the exact failure message.

How do I support passing a unique job name via environment variable to a Spring Batch Job?

I'm just getting started with using Spring Batch. I'm working on a command line launcher using AWS Batch with a Docker image. Trying to just sort the job instance naming.
Would it be acceptable to use a #Value for the below literal string in the jobBuilder? Essentially I'm passing in S3 File keys which will be unique values already as I have a task that's grabbing the file before my FlatFileReader runs. The goal being to facilitate retries against the job when required due to a failure.
#Bean
public Job jobParametersJob() {
return jobBuilderFactory.get("PassedInValue")
.start(step1())
.next(step2())
.next(step3())
.build();
}
I ended up solving by using a job incrementer that implements JobParametersIncrementer. Note in my case, I'm not currently passing in any job parameters so this is setting them here as my parameters are currently just passed in via environment variables to the docker container.
public class JobIncrementer implements JobParametersIncrementer {
#Value("${s3filekey}")
String s3filekey;
#Override
public JobParameters getNext(JobParameters jobParameters) {
return new JobParametersBuilder().addString("s3filekey",s3filekey).toJobParameters();
}...//then in job configuration...
#Bean
public Job jobParametersJob() {
return jobBuilderFactory.get("jobParametersJob")
.incrementer(jobIncrementer)
.start(step1())
.next(step2())
.next(step3())
.build();
}

loadbalanced ribbon client initialization against discovery service (eureka)

I have service which runs some init scripts after application startup (implemented with ApplicationListener<ApplicationReadyEvent>). In this scripts I need to call another services with RestTemplate which is #LoadBalanced. When the call to service is invoked there's no information about instances of remote service because discovery server was not contacted at that time (I guess).
java.lang.IllegalStateException: No instances available for api-service
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:79)
So is there way how to get list of available services from discovery server at application startup, before my init script will execute?
Thanks
edit:
The problem is more related to fact, that in current environment (dev) all services are tied together in one service (api-service). So from within api-service I'm trying to call #LoadBalanced client api-service which doesn't know about self? Can I register some listener or something similar to know when api-service (self) will be available?
here are the sample applications. I'm mainly interested how to have working this method
edit2:
Now there could be the solution to create EurekaListener
public static class InitializerListener implements EurekaEventListener {
private EurekaClient eurekaClient;
private RestOperations restTemplate;
public InitializerListener(EurekaClient eurekaClient, RestOperations restTemplate) {
this.eurekaClient = eurekaClient;
this.restTemplate = restTemplate;
}
#Override
public void onEvent(EurekaEvent event) {
if (event instanceof StatusChangeEvent) {
if (((StatusChangeEvent) event).getStatus().equals(InstanceInfo.InstanceStatus.UP)) {
ResponseEntity<String> helloResponse = restTemplate.getForEntity("http://api-service/hello-controller/{name}", String.class, "my friend");
logger.debug("Response from controller is {}", helloResponse.getBody());
eurekaClient.unregisterEventListener(this);
}
}
}
}
and then register it like this:
EurekaEventListener initializerListener = new InitializerListener(discoveryClient, restTemplate);
discoveryClient.registerEventListener(initializerListener);
However this is only executed only when application is registered to discovery service first time. Next time when I stop the api-service and run it again, event is not published. Is there any other event which can I catch?
Currently, in Camden and earlier, applications are required to be registered in Eureka before they can query for other applications. Your call is likely too early in the registration lifecycle. There is an InstanceRegisteredEvent that may help. There are plans to work on this in the Dalston release train.

Cannot create an object of class SVM in Scheduler task

I have a TYPO3 extension providing a scheduler task (extension scheduler 6.2.0).
In this task I have following strage problem:
private $svm;
...
$this->svm = new \SVM();
When this line is executed during task execution (started from cron job) program hangs up and does nothing. No exception, no error. It is just waiting for something.
If this line is executed within extension - an object is created.
If I start scheduler task manually in TYPO3 back-end - an object is also created.
It looks like during CLI execution class SVM is unknown. But then there should be an error...
If the class SVMis unknown, an error would occur and nothing would wait. I propose that you debug that and check, e.g. with class_exists($this->svm) if this class exists.
Without knowing more it is hard to help more.