JujaLabs / juja-platform

0 stars 7 forks source link

Implement ARC-F5 feature (receive, store and regularly update list of slack channels) #34

Open VadimDyachenko opened 6 years ago

VadimDyachenko commented 6 years ago

User story:

Я как система хочу чтобы список каналов сихнронихировался со слаком для чтобы иметь последнюю верную копию. по расписанию, по http, в первоначальном формате, для того чтобы потом выбирать нужную доп. информацию

0. to recieve list of channels from slack and save the list of channels in raw format to the database  
1. not used
2.  
        - new model for parse the [response ](https://api.slack.com/methods/channels.list)
           ChannelsRawSlackResponse{
               private String ok;
               private List> channels;
               private Map responseMetadata;
           }

         - new Entity for save received channels to the db
           RawChannel{
               @Id
               private String id;
               private Map channel;
           }

     - new SlackApiClient
            The class receive List of channels use restTemplate and url https://slack.com/api/channels.list?
            token=slackToken
            method:
            List receiveChannelsList();

     - SlackArchiveRepository split to MessageRepository and ChannelRepository
     - edit ChannelRepository 
            add method -
            void saveRawChannels(List channels);
            the method must just rewrite collection raw-channels.

     - SlackArchiveService split to MessageService and ChannelService
     - edit ChannelService
            add method

           add new method  public void saveChannels(List channelsDTO)
     - new Scheduler service
            you should inject the beans SlackApiClientService and ChannelService
            the service must start by schedule, recieve channelList using SlackApiService and save the channels using channelService
     - new SchledulerConfig 
            sample code:
@Configuration
@EnableScheduling
public class SchedulerConfig implements SchedulingConfigurer {

    private final int POOL_SIZE = 2;

    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
        threadPoolTaskScheduler.setThreadNamePrefix("sheduled-get-slack-channels-task-pool-");
        threadPoolTaskScheduler.initialize();

        scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
    }
}

3.
we save to db raw channel list
use new mongo db collection raw-channels
use RestTemplate to get list of channels 
sort out SimpleSlackApi method getChannels() returns channels in solid list or in pieces.

4.  -save channels in raw format
    -when we save the received channel list we just rewrite old channel list.
    -the task runs by schedule with specified fixed rate 5h
petrokramar commented 6 years ago

My version of user story:

1) What is this feature/fix provided for?

Save channels list from raw channels from collection "raw_channels"

2) List the objects you want to add or change, use appropriate API annotations

**Model**

    Add class Channel

    @Document
    public class Channel {
        @Field("_id")
        private String id;
        private String name;
        private String ts;

    where ts - max ts of message which is stored in raw_messages collection

**Repository**

    ChannelsRepository  

    implement method List<Channel> getRawChannels()  - collection "raw_channels"

    implement method void saveChannels(List<Channels> channels)  - collection "channels"

**Service**

    ChannelsService 

    implement method List<Channel> getRawChannels()

    implement method void saveChannels(List<Channels> channels)
    This method save list of all channels.

**Controller**  

    No changes

3) Are there any special requirements or constraints?

ChannelsService method saveChannels runs on schedule.

4) What behavior do you expect? Any examples?

Document example:

{ "_id" : "C703E6B51", "name" : "general" "ts" : "1515767002.000721", }

, where "ts" is max ts of loading channels list from slack

hamster4n commented 6 years ago

1. What is this feature/fix provided for?

Save channels list from raw channels from collection "raw_channels"

2. List the objects you want to add or change, use appropriate API annotations

Model

Add class Channel { @Field("_id") private String id; private String name; private String ts;

where ts - max ts of message which is stored in raw_messages collection Repository

ChannelsRepository

implement method List getRawChannels() - collection "raw_channels"

implement method void saveChannels(List channels) - collection "channels"

Service

ChannelsService

implement method List getRawChannels()

implement method void saveChannels(List channels) This method save list of all channels.

Controller

No changes

3. Are there any special requirements or constraints?

ChannelsService method saveChannels runs on schedule.

4. What behavior do you expect? Any examples?

Document example:

{ "_id" : "C703E6B51", "name" : "general" "ts" : "1515767002.000721", }

, where "ts" is max ts of loading channels list from slack