Skip to main content

Generate State Workflow

Overview

User Code: com.finmars.standard-workflow:generate-state

This script is designed to generate state files for state managers. It processes input data to create a structured state file that includes information about workers and their respective states.

Workflow Function

The main workflow function is a task that generates the state file based on the provided payload.

Parameters:

  • payload: A dictionary containing the necessary information for state generation.

Process:

  1. Validates the presence of a payload
  2. Retrieves the input data from the specified path input_file
  3. Generates a new state file using the generate_state_file function
  4. Saves the generated state file
  5. Updates the status of the operation in the state file

Helper Functions

  1. get_first_transaction_date: Retrieves the earliest transaction date from the API.
  2. get_next_date: Calculates the next date based on the given periodicity.
  3. get_period_end_date: Calculates the end date of a period based on the start date and periodicity.
  4. build_url: Constructs the full API URL for a given endpoint.
  5. get_headers: Generates headers with authorization token for HTTP requests.
  6. log_message: Logs a message with a timestamp.
  7. save_file: Saves data to a specified file path in JSON format.
  8. get_files: Lists files in the specified directory.
  9. get_folders: Lists directories in the specified path.
  10. get_data: Reads data from a JSON file.