Search in sources :

Example 1 with ReturnCode

use of com.github.robozonky.api.ReturnCode in project robozonky by RoboZonky.

the class App method main.

public static void main(final String... args) {
    App.LOGGER.debug("Current working directory is '{}'.", System.getProperty("user.dir"));
    App.LOGGER.debug("Running {} {} v{} on {} v{} ({}, {} CPUs, {}, {}).", System.getProperty("java.vm.vendor"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"), Runtime.getRuntime().availableProcessors(), Locale.getDefault(), Charset.defaultCharset());
    final ReturnCode code = configure(args).map(App::execute).orElse(ReturnCode.ERROR_SETUP);
    // call the core code
    App.exit(code);
}
Also used : ReturnCode(com.github.robozonky.api.ReturnCode)

Example 2 with ReturnCode

use of com.github.robozonky.api.ReturnCode in project robozonky by RoboZonky.

the class App method execute.

private static ReturnCode execute(final InvestmentMode mode) {
    App.SHUTDOWN_HOOKS.register(() -> Optional.of((r) -> Scheduler.inBackground().close()));
    Events.fire(new RoboZonkyStartingEvent());
    try {
        ensureLiveness();
        Scheduler.inBackground().submit(new UpdateMonitor(), Duration.ofDays(1));
        App.SHUTDOWN_HOOKS.register(new Management(LIFECYCLE));
        final String sessionName = Events.getSessionInfo().flatMap(SessionInfo::getName).orElse(null);
        App.SHUTDOWN_HOOKS.register(new RoboZonkyStartupNotifier(sessionName));
        return mode.apply(LIFECYCLE);
    } catch (final Throwable t) {
        LOGGER.error("Caught unexpected exception, terminating daemon.", t);
        return ReturnCode.ERROR_UNEXPECTED;
    }
}
Also used : RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SystemExitServiceLoader(com.github.robozonky.util.SystemExitServiceLoader) Scheduler(com.github.robozonky.util.Scheduler) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) CommandLine(com.github.robozonky.app.configuration.CommandLine) Charset(java.nio.charset.Charset) Locale(java.util.Locale) Duration(java.time.Duration) Management(com.github.robozonky.app.management.Management) SystemExitService(com.github.robozonky.util.SystemExitService) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMode(com.github.robozonky.app.configuration.InvestmentMode) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) Management(com.github.robozonky.app.management.Management)

Example 3 with ReturnCode

use of com.github.robozonky.api.ReturnCode in project robozonky by RoboZonky.

the class DaemonInvestmentModeTest method get.

@Test
void get() throws Exception {
    final Authenticated a = mockAuthentication(mock(Zonky.class));
    final Investor.Builder b = new Investor.Builder().asDryRun();
    final ExecutorService e = Executors.newFixedThreadPool(1);
    final PortfolioUpdater p = mock(PortfolioUpdater.class);
    try {
        final DaemonInvestmentMode d = new DaemonInvestmentMode(t -> {
        }, a, p, b, mock(StrategyProvider.class), Duration.ofSeconds(1), Duration.ofSeconds(1));
        // will block
        final Future<ReturnCode> f = e.submit(() -> d.apply(lifecycle));
        assertThatThrownBy(() -> f.get(1, TimeUnit.SECONDS)).isInstanceOf(TimeoutException.class);
        // unblock
        lifecycle.resumeToShutdown();
        // should now finish
        assertThat(f.get()).isEqualTo(ReturnCode.OK);
        verify(p).run();
    } finally {
        e.shutdownNow();
    }
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) ReturnCode(com.github.robozonky.api.ReturnCode) ExecutorService(java.util.concurrent.ExecutorService) Investor(com.github.robozonky.app.investing.Investor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

ReturnCode (com.github.robozonky.api.ReturnCode)3 RoboZonkyStartingEvent (com.github.robozonky.api.notifications.RoboZonkyStartingEvent)1 SessionInfo (com.github.robozonky.api.notifications.SessionInfo)1 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1 CommandLine (com.github.robozonky.app.configuration.CommandLine)1 InvestmentMode (com.github.robozonky.app.configuration.InvestmentMode)1 Investor (com.github.robozonky.app.investing.Investor)1 Management (com.github.robozonky.app.management.Management)1 Lifecycle (com.github.robozonky.app.runtime.Lifecycle)1 UpdateMonitor (com.github.robozonky.app.version.UpdateMonitor)1 Zonky (com.github.robozonky.common.remote.Zonky)1 Scheduler (com.github.robozonky.util.Scheduler)1 SystemExitService (com.github.robozonky.util.SystemExitService)1 SystemExitServiceLoader (com.github.robozonky.util.SystemExitServiceLoader)1 Charset (java.nio.charset.Charset)1 Duration (java.time.Duration)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 ExecutorService (java.util.concurrent.ExecutorService)1