Giter Site home page Giter Site logo

banking-challenge-services's Introduction

banking-challenge-services

Desenho de arquitetura

Macro

aws

Foi utilizado um message broker RabbitMQ para reduzir o acoplamento do sistema

Não consegui instalar um certificado SSL na instância EC2, então o projeto do webhook ficou local e foi utilizado ngrok para expor o serviço para internet.

Foi utilizado um TimerTask com a biblioteca Joda para verificar se passaram 3h desde o último schedule e se passaram 24h desde o primeiro schedule.

timer.schedule(new TimerTask() {
            @Override
            public void run() {
                try {

                    var currentDay = DateTime.now().dayOfYear().get();

                    if (beginDay != currentDay) {
                        System.out.println("Scheduler encerrado 24H depois.");
                        timer.cancel();
                        timer.purge();
                    }

                    var scheduledInvoice = scheduleService.isScheduledTime();
                    
                    if (scheduledInvoice != null) {
                        
                        wrapper.lastScheduled = scheduledInvoice.id;
                        
                        var newInvoices = createInvoicesForRandomCustomers();

                        scheduleService.setLastId(Iterables.getLast(newInvoices).id);
                    }
                    
                } catch (MalformedURLException ex) {
                    Logger.getLogger(InvoiceScheduler.class.getName()).log(Level.SEVERE, null, ex);
                } catch (Exception ex) {
                    Logger.getLogger(InvoiceScheduler.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }, 0, 2000);
public Invoice isScheduledTime() throws MalformedURLException {

        var lastItemCreated = hasLastItem();

        if (lastItemCreated != null) {

            String timestamp = hasLastItem().created;

            timestamp = String.valueOf(new DateTime(timestamp).getMillis());
//      timestamp para testar:      timestamp = String.valueOf(new DateTime("2022-03-01T02:59:02.815762+00:00").getMillis());

            Long lastTime = Long.parseLong(timestamp);

            var now = DateTime.now(DateTimeZone.UTC);

            var currentTime = now.getMillis();

            var interval = new Interval(lastTime, currentTime).toDurationMillis();

            // 1h=3600000 / 3h=10800000
            if (interval >= 10800000) {
                lastId = "";
                if (!(lastId.equals(lastItemCreated.id))) {
                    lastId = lastItemCreated.id;
                    System.out.println("*=*=*=*=*=*=*=*=Return the scheduled invoice *=*=*=*=*=*=*=*=");
                    return lastItemCreated;
                }
            }
        }

        return null;
    }

banking-challenge-services's People

Contributors

lucas-salves avatar

Stargazers

Bruno Mendes avatar

Watchers

 avatar

banking-challenge-services's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.