lundi 3 février 2020

Pythonic way to handle/spread alerts class in multiple modules

I have a class to handle alerts that, at the end of the process, will be sent in an email. This alerts are list that are updated during the process execution.

The point is that the process uses different modules in different files so...

My question is: what is the pythonic way of handling this alerts class?

  • Declare it at the beginnig of the process and pass it as argument to the different modules handlers?
  • Maybe create it as Singleton?
  • Any other idea is obviously welcome!

Thank you in advance!

Design Pattern and Database structure for developing a Status table

Making using Java and Oracle as there are 5 scheduler jobs running daily

The status table could include following columns:

-   Job Name (Name of Job/Unique ID or SHort Name)
-   Start Date Time 
-   Status  
-   Finish Date Time 
-   Remarks 

Business Logic:

•   On Start of job, insert a row in status table with status as Start and datetime. 
•   On End of Job, Update the row with status as `success`
•   On Exception, Update the row with status as `failed` with exception message.
* The next day next row will be created

Other applications need to pick records based on status table success.

Is there any issue in design or DB Structure or can it be handle in more elegant way and which design pattern should be used in this case?

File content validation - Spring best practice

I'm kinda new in Spring and we start to use Spring framework at work.

We're working on a self-service installation website that performs these steps: accept file, parse, store locally, "install"(via running a Linux shell script).

My controller accepts the file and I'm using a validator to check if the file is empty and the type of content, then I extract from the file the fields that I need to validate against my DB, meaning let's say I extracted the server name from the text file, I need to validate if the server name exists in the DB.

My question is the following:

What is the best practice to handle file content validation?

  1. Put all checks in the FileValidator that already checks if the file is empty, etc.
  2. Put the checks in the service class that I wrote to extract the file content.
  3. use custom annotation validation on my VO

Should the file content validation be in the service layer with the extraction functions?

In another topic:

I wrote 2 service classes to extract the file content (e.g ServerExtractService & ModeExtractService), I used services since I'm accessing repositories, should I use a utility class instead?

Thanks in advance.

When use service layer in laravel mvc framework

I have same code for my api and web

So I try to use Service layer in my project

I read a lot of open source project made with Laravel and there is no services in them and I'm confused why?

I there another approach in laravel for try prevent duplicate code? Is there a better replacement for Service layer in laravel?

dimanche 2 février 2020

Why is it possible to assign a temporary value to a reference by passing it via the constructor?

class MoveSemantic{

public:

// For inserting a value
MoveSemantic(short &value);
MoveSemantic(short &&value);

short &storedValue;

};

// Reference forced to initialize
MoveSemantic::MoveSemantic(short &value) : storedValue(value) {}
MoveSemantic::MoveSemantic(short &&value) : storedValue(value) {}

// Passing a RValue => Assiging to reference => Is this safe ?
MoveSemantic semantik(100);
cout << semantik.storedValue; // 100

I lately discovered that its possible to assign a temporary value to a reference inside a class by abusing the rvalue semantics... But why is this possible ? How does the memory behaves ?

Does this extend the lifetime of the temporary variable "100" due to its assigning ? How safe is this ? And when does the temporary value gets destroyed by the scope ?

When should I allow Post Object vs Array of objects in a REST API?

When is it considered better to accept array of a given object over a single object of the same type. Is there a strict line or it's up for interpretation?

How to call a rest api for multiple databases?

I have to create a RESTful API for a system which is maybe a bit unusual in the sense that each client using this system has their own database. (A client is like a company, with many users in it). So there is a master database which specifies, for each client, which database it must connect to. All clients databases are identical (except for the data of course).

I'm wondering how I should handle this... Normally, when an app consumes a Web API, you might have something like this: