<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[nodejs שמירת נתונים לבסיס נתונים לפני אתחול השרת]]></title><description><![CDATA[<p dir="auto">האם יש מצב ליצור שבעת עצירת תהליך NODEJS מכל סיבה שהיא (בדרך כלל בגלל אתחול), נתונים שהיו שמורים בתהליך יישמרו לבסיס הנתונים, כדי שאוכל לשחזר אותם לאחר האתחול?</p>
]]></description><link>https://tchumim.com/topic/6745/nodejs-שמירת-נתונים-לבסיס-נתונים-לפני-אתחול-השרת</link><generator>RSS for Node</generator><lastBuildDate>Tue, 19 May 2026 06:39:24 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/6745.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Oct 2019 19:14:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to nodejs שמירת נתונים לבסיס נתונים לפני אתחול השרת on Wed, 02 Sep 2020 07:12:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/%D7%99%D7%95%D7%A1%D7%A3-%D7%91%D7%9F-%D7%A9%D7%9E%D7%A2%D7%95%D7%9F">@<bdi>יוסף-בן-שמעון</bdi></a> אמר ב<a href="/post/78655">nodejs שמירת נתונים לבסיס נתונים לפני אתחול השרת</a>:</p>
<blockquote>
<p dir="auto"><a href="https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits</a></p>
</blockquote>
<p dir="auto">הבעיה שהייתה לי שם שזה ביטל את הכיבוי לחלוטין והיו צריכים להשמיד את התהליך בכדי לעצור אותו לגמרי.<br />
כעת נכנסתי לזה שוב ועשיתי פטנט פשוט, שלאחר ביצוע השמירה הנדרשת, אני מסיר את האירוע מהכיבוי ואז אני מכבה פשוט.<br />
ב"ה עובד חלק.<br />
בכל אתחול של השרת אני קורא את הנתונים השמורים, ורק בעת כיבוי אני שומר בכדי לשחזר אותם להפעלה החוזרת.<br />
להלן הקוד</p>
<pre><code>
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) =&gt; {
    process.on(eventType, (eventType) =&gt; {
        let data = JSON.stringify(myData.ActiveCalls);
        fs.writeFile(ActiveCallsFile, data, function (err) {
            if (err) {
                console.log('There has been an error saving your configuration data.');
                console.log(err.message);
                // return;
            }
            process.removeAllListeners('exit');
            process.exit();
        });
    });
})
</code></pre>
<p dir="auto">ולהלן הקוד בתחילת הקובץ עבור האתחול</p>
<pre><code>
let ActiveCallsFile = './projects/bs/ActiveCalls.json';
try {
    let loadData = fs.readFileSync(ActiveCallsFile);
    myData.ActiveCalls = JSON.parse(loadData);
} catch (err) {
}
</code></pre>
]]></description><link>https://tchumim.com/post/109696</link><guid isPermaLink="true">https://tchumim.com/post/109696</guid><dc:creator><![CDATA[חוקר]]></dc:creator><pubDate>Wed, 02 Sep 2020 07:12:14 GMT</pubDate></item><item><title><![CDATA[Reply to nodejs שמירת נתונים לבסיס נתונים לפני אתחול השרת on Tue, 22 Oct 2019 19:51:34 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits</a></p>
]]></description><link>https://tchumim.com/post/78655</link><guid isPermaLink="true">https://tchumim.com/post/78655</guid><dc:creator><![CDATA[יוסף בן שמעון]]></dc:creator><pubDate>Tue, 22 Oct 2019 19:51:34 GMT</pubDate></item></channel></rss>