<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: rajentrivedi</title>
    <description>The latest articles on DEV Community by rajentrivedi (@rajentrivedi).</description>
    <link>https://dev.to/rajentrivedi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F691619%2F0d3c9ec5-fe00-499d-943b-7bc604ac7b44.jpeg</url>
      <title>DEV Community: rajentrivedi</title>
      <link>https://dev.to/rajentrivedi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajentrivedi"/>
    <language>en</language>
    <item>
      <title>Automating Laravel Queue Worker Restarts with a queue-watch</title>
      <dc:creator>rajentrivedi</dc:creator>
      <pubDate>Thu, 19 Sep 2024 11:40:46 +0000</pubDate>
      <link>https://dev.to/rajentrivedi/automating-laravel-queue-worker-restarts-with-a-queue-watch-2459</link>
      <guid>https://dev.to/rajentrivedi/automating-laravel-queue-worker-restarts-with-a-queue-watch-2459</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28b45swbb0jkezcilefc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28b45swbb0jkezcilefc.png" alt="queue-watch" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Managing queue workers in a Laravel application can sometimes be tedious, especially when dealing with long-running processes. A common challenge is ensuring that workers are restarted whenever there are changes in the jobs, events, or listeners folders. Restarting workers manually can be inefficient and prone to oversight, potentially leading to application inconsistencies or stale queue processing.&lt;/p&gt;

&lt;p&gt;To solve this problem, I’ve developed a Laravel package that automates this process. This package detects file changes within your Laravel application’s jobs, events, and listeners folders and automatically restarts the queue worker when changes are detected. In this blog post, I’ll walk you through the need for this package, how it works, and how to integrate it into your Laravel project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do You Need This Package?
&lt;/h2&gt;

&lt;p&gt;Laravel’s queue workers are designed to run for extended periods, handling background tasks like sending emails, processing orders, and more. However, these workers don’t automatically detect code changes. If you modify your job classes, events, or listeners, the running queue worker won't pick up these changes until you manually restart it.&lt;/p&gt;

&lt;p&gt;This can lead to several problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Outdated code: The worker continues running with old logic, which may not match the latest application updates.&lt;/li&gt;
&lt;li&gt;Inconsistent-behavior: The application may process jobs incorrectly or skip new features because the worker isn’t aware of the changes.&lt;/li&gt;
&lt;li&gt;Developer overhead: Restarting queue workers manually can become an extra burden, especially in larger teams and projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To address this, my package will monitor for file changes and trigger an automatic restart whenever necessary. This removes the need for manual intervention, ensuring that the worker always uses the latest code.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Package Works
&lt;/h2&gt;

&lt;p&gt;At a high level, the package performs the following actions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monitoring Specific Folders: The package watches for any file changes within the app/Jobs, app/Listeners, and app/Events directories. These are the folders most commonly involved in queue processing logic.&lt;/li&gt;
&lt;li&gt;Detecting Changes: When a file in any of these directories is added, modified, or deleted, the package detects this event.&lt;/li&gt;
&lt;li&gt;Restarting the Queue Worker: Once a change is detected, the package automatically triggers the queue worker restart. This ensures that the worker is always running with the latest codebase.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Installing the package is straightforward. Start by requiring the package via Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require rajentrivedi/queue-watch &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, you can publish the package’s configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan vendor:publish &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"queue-watch-config"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Configuration&lt;/strong&gt;&lt;br&gt;
By default, the package will monitor the app/Jobs, app/Listeners, and app/Events directories. However, if you need to customize this behavior (e.g., monitor additional directories or exclude certain files), you can do so in the configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'directories'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
        app_path&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Jobs'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
        app_path&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Events'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
        app_path&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Listeners'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
    &lt;span class="o"&gt;]&lt;/span&gt;,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Artisan Command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan queue:work:watch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;br&gt;
Once the package is installed, configured and run above given artisan command, it runs automatically in the background, constantly watching for changes in the specified folders. No manual action is required beyond the initial setup.&lt;/p&gt;

&lt;p&gt;To test the package, simply make a change to a job, event, or listener file. You should see the queue worker automatically restart within a few seconds, reflecting the new changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Automating Queue Worker Restarts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved Efficiency&lt;/strong&gt;: Automating the process of queue worker restarts ensures that developers can focus on writing code rather than managing queue processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Errors&lt;/strong&gt;: The package minimizes the risk of bugs or unexpected behavior caused by outdated workers running old code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smoother Development&lt;/strong&gt;: In larger teams or complex projects, this package removes the overhead of manually restarting workers, ensuring smoother deployment workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would love to hear feedback from the community on other potential features or improvements!&lt;/p&gt;

&lt;p&gt;This Laravel package simplifies queue worker management by automating the restart process whenever key files are changed. It reduces developer effort, ensures that workers are always running the latest code, and ultimately leads to a more robust and efficient application.&lt;/p&gt;

&lt;p&gt;Feel free to give it a try and share your thoughts. You can find the source code here on &lt;a href="https://github.com/rajentrivedi/queue-watch" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Stay tuned for future updates as I continue improving the package based on user feedback!&lt;/p&gt;

&lt;p&gt;This package is perfect for anyone who works with queues in Laravel and wants to streamline their development and deployment processes. By integrating this tool, you can ensure that your queue workers are always running with the latest code, reducing errors and improving efficiency.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Supercharge Your Tokenization with TokenizerX: Now Supporting Multiple OpenAI Models</title>
      <dc:creator>rajentrivedi</dc:creator>
      <pubDate>Tue, 05 Dec 2023 06:19:13 +0000</pubDate>
      <link>https://dev.to/rajentrivedi/supercharge-your-tokenization-with-tokenizerx-now-supporting-multiple-openai-models-517j</link>
      <guid>https://dev.to/rajentrivedi/supercharge-your-tokenization-with-tokenizerx-now-supporting-multiple-openai-models-517j</guid>
      <description>&lt;p&gt;I am thrilled to announce a significant update to our Laravel package, TokenizerX! With the latest release, TokenizerX has evolved to support a variety of OpenAI models, unleashing even more powerful tokenization capabilities in your applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is TokenizerX?&lt;/strong&gt;&lt;br&gt;
TokenizerX is a Laravel package designed to simplify and enhance tokenization processes in your projects. Whether you're working on natural language processing, machine learning, or any application that requires breaking down text into individual tokens, TokenizerX is your go-to solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introducing Support for Multiple OpenAI Models&lt;/strong&gt;&lt;br&gt;
One of the standout features of TokenizerX is its newfound compatibility with a range of OpenAI models. This means you can now choose the model that best fits your requirements, opening up possibilities for diverse use cases and improved language understanding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supported OpenAI Models&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;gpt-4&lt;/li&gt;
&lt;li&gt;gpt-3.5-turbo&lt;/li&gt;
&lt;li&gt;text-davinci-003&lt;/li&gt;
&lt;li&gt;text-davinci-002&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and many more supported OpenAI models, please visit the &lt;a href="https://github.com/rajentrivedi/tokenizer-x/tree/rajen-gpt-4"&gt;TokenizerX&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whether you're seeking the cutting-edge capabilities of GPT-4 or the efficiency of smaller models like text-ada-001, TokenizerX has you covered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy Integration and Usage&lt;/strong&gt;&lt;br&gt;
Getting started with TokenizerX is a breeze. Simply install the package via Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require rajentrivedi/tokenizer-x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With TokenizerX, you can easily calculate OpenAI tokens for a given prompt, helping you manage API token limits and generate accurate responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Rajentrivedi\TokenizerX\TokenizerX;

// Default usage with gpt-3 model
$tokenCount = TokenizerX::count("How are you?");

// Specify a different OpenAI model
$tokenCountGPT4 = TokenizerX::count("How are you?", "gpt-4");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Upgrade and Explore&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ready to take advantage of TokenizerX's enhanced capabilities? Upgrade your package to the latest version and explore the world of tokenization with support for multiple OpenAI models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Get Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For detailed installation instructions, configuration options, and usage examples, refer to the &lt;a href="https://github.com/rajentrivedi/tokenizer-x/tree/rajen-gpt-4"&gt;TokenizerX documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;TokenizerX continues to evolve, providing developers with a versatile tool for effective tokenization. Whether you're a seasoned developer or just starting, TokenizerX's support for various OpenAI models makes it a valuable asset for your projects.&lt;/p&gt;

&lt;p&gt;Explore the possibilities, experiment with different models, and let TokenizerX transform the way you handle text in your Laravel applications!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
      <category>openai</category>
    </item>
    <item>
      <title>Introducing TransactionX: A Laravel Middleware for Effortless Database Transactions</title>
      <dc:creator>rajentrivedi</dc:creator>
      <pubDate>Fri, 24 Nov 2023 10:51:58 +0000</pubDate>
      <link>https://dev.to/rajentrivedi/introducing-transactionx-a-laravel-middleware-for-effortless-database-transactions-5dbo</link>
      <guid>https://dev.to/rajentrivedi/introducing-transactionx-a-laravel-middleware-for-effortless-database-transactions-5dbo</guid>
      <description>&lt;p&gt;As developers, we often find ourselves facing challenges that prompt us to seek elegant and efficient solutions. During the development of a substantial Laravel project, I encountered a recurring need for database transactions across various pages. Adhering to the DRY (Don't Repeat Yourself) principle, I realized the opportunity to streamline this process and enhance code cleanliness. This realization led to the creation of the TransactionX package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The DRY Dilemma&lt;/strong&gt;&lt;br&gt;
In the course of working on a large Laravel project, managing database transactions became a frequent task. Each time I needed to implement a transaction, I found myself duplicating code and violating the DRY principle. It was clear that a more systematic and reusable approach was necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter TransactionX&lt;/strong&gt;&lt;br&gt;
TransactionX is a Laravel middleware designed to simplify the implementation of database transactions across your application. This middleware provides an elegant solution for handling transactions seamlessly, reducing redundancy and enhancing the overall maintainability of your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automatic Transactions&lt;/p&gt;

&lt;p&gt;TransactionX takes care of starting and managing transactions automatically. You no longer need to manually implement beginTransaction(), commit(), and rollBack() for each operation that involves database changes. The middleware intelligently starts a transaction before the route is executed and commits or rolls back based on the route's outcome.&lt;/p&gt;

&lt;p&gt;Conditional Execution&lt;/p&gt;

&lt;p&gt;Transactions are applied selectively to non-GET requests, ensuring that read-only operations remain unaffected. This optimization minimizes the impact on database interactions, focusing transactions on data-altering requests where they are most needed.&lt;/p&gt;

&lt;p&gt;Error Handling&lt;/p&gt;

&lt;p&gt;TransactionX handles exceptions and errors gracefully. If an exception occurs during the route execution or if there are errors reported by Laravel's error handling system, the middleware rolls back the transaction, maintaining a consistent state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started with TransactionX&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require rajentrivedi/transactionx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Middleware Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apply the TransactionMiddleware middleware to the routes where you want to enable automatic transactions. Transactions will be applied to non-GET requests only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::post('users/changeStatus', 'UserController@changeStatus')-&amp;gt;name('change.status')-&amp;gt;middleware('transaction-x');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Enjoy Clean Transactions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With TransactionX in place, you can now focus on building your application logic without the need for explicit transaction management. The middleware ensures that your database transactions are handled consistently and efficiently&lt;/p&gt;

&lt;p&gt;TransactionX emerged from the real-world need for a more elegant and systematic approach to handling database transactions in Laravel projects. By automating transactions and adhering to the DRY principle, this middleware contributes to code cleanliness and maintainability. Try out TransactionX in your Laravel project and experience the simplicity of database transactions done right.&lt;/p&gt;

&lt;p&gt;For contributions, issues, or feedback, feel free to visit the &lt;a href="https://github.com/rajentrivedi/transaction-x"&gt;TransactionX GitHub&lt;/a&gt; repository.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>package</category>
      <category>developers</category>
    </item>
  </channel>
</rss>
